'Array search and replace with Sublime Text's regular expression

How can I search for multiple words and replace each one by a specific word using regular expression? In PHP it would be :

$string = 'The quick bar foo jumps over the bazzy qux';
$patterns = array('foo', 'bar');
$replacements = array('baz', 'qux');
echo preg_replace($patterns, $replacements, $string);
// Outputs: The quick qux baz jumps over the bazzy qux

I would like to do it inside of Sublime Text which uses Boost Syntax for seach and replace (reference) which seems to be pearl syntax.



Solution 1:[1]

I would use the regex enabled search to find all of one word then hit find all. Then simply type your replacement word in. Repeat for each word you want to replace.

Solution 2:[2]

At least you can do this to replace an array of possible strings with a specific replacement:

Find:

foo|bar

Replace:

cow

This will replace all instances of foo and bar with cow.

I'm not sure how to fine-tune the replacements specific to foo or bar.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Threadicide
Solution 2 Isaac Brockman