1

I want to find and replace several words at the same time in sublime, for example I want to replace word1,word2,word3 by word4,word5,word6 at the same time instead of doing them in 3 steps. Can I do it in sublime? if not how can I come up with a regexp to do this? Thank you

MattDMo
  • 100,794
  • 21
  • 241
  • 231
Said Saifi
  • 1,995
  • 7
  • 26
  • 45
  • 2
    Just to clear it out: Sublime Text replacement patterns only allow [Perl Format String Syntax](http://www.boost.org/doc/libs/1_62_0/libs/regex/doc/html/boost_regex/format/perl_format.html). Notepad++ replacement patterns support [Boost-Extended Format String Syntax](http://www.boost.org/doc/libs/1_62_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html) and can do what you need with the simple regex S&R. See [How to use conditionals when replacing in Notepad++ via regex](http://stackoverflow.com/questions/37160927/37161309#37161309). – Wiktor Stribiżew Dec 03 '16 at 11:01

2 Answers2

3

In this case sed command might help you.

sed -i -e 's/word1/replace1/g' fileName && sed -i -e 's/word2/replace2/g' fileName && ...

and this goes on how many of words you need to replace, you can. Just run this on your terminal

Example:

this is a content of file. File name is t.txt

I want to replace this with that and file with FILE. then command will be :

sed -i -e 's/this/that/g' t.txt && sed -i -e 's/file/FILE/g' t.txt

output will be :

that is a content of FILE. File name is t.txt

rubayet.R
  • 113
  • 1
  • 9
0

You can use the pattern word1(.*)word2(.*)word3 to match the words, if the words to be replaced come in sequential order with or without some characters in between and use word4\1word5\2word6\3 as replacement.

The pattern has used 3 capture groups to match characters if any between the words to be replaced. \1,\2 and \3 represent each captured group.

Here, the replacement pattern says that the matched text has to be replaced with the sequence of word4 followed by the characters captured in first capture group i.e. the characters if any between the word 1 and word2, followed by word5 and so on.

Naveed S
  • 5,106
  • 4
  • 34
  • 52
  • thank you, but I want to replace several word1 and several word2 and several word3 they can't be combined to match a certain pattern as you specified – Said Saifi Dec 03 '16 at 10:22