Isioma Nnodum
Isioma Nnodum

Reputation: 1318

Multiple Regular Expression Search and Replace

Is there a way in Sublime Text to execute multiple regular expression search and replace queries at once.

For example I want to (in the order listed)

  1. Find strings matching regex1 and replace them with regex1replacement
  2. Find strings matching regex2 and replace them with regex2replacement
  3. Find strings matching regex3 and replace them with regex3replacement
  4. Find strings matching regexN and replace them with regexNreplacement

At once.

The string: "blah regex1, bloo regex2, bleep regex3" Would become : "blah regex1replacement, bloo regex2replacement, bleep regex3replacement"

This is something that can be easily scripted, but I currently don't have that freedom.

Upvotes: 0

Views: 405

Answers (1)

000
000

Reputation: 27247

edit: Oh sorry I missed that you want this in sublime text. Sorry!

sed 's/regex1/regex1replacement/g;s/regex2/regex2replacement/g;s/regex3/regex3replacement/g;'

For a cleaner script, I think this will work, but I haven't tested:

sed "s/regex1/regex1replacement/g; \
     s/regex2/regex2replacement/g; \
     s/regex3/regex3replacement/g;"

Upvotes: 1

Related Questions