Search code examples
regexreplacefindsublimetext3

How to replace text wrapped by tabs using regular expression and Sublime Text?


I have the following pattern:

SomeText    SomeText    SomeText
SomeProp    SomeProp    SomeProp
Property    Property    Property

Each word are separated by a tab \t.

I need to replace the second/middle word by prefix + middle word + suffix.

I use this regex to select the second word:

\t(\w)*\t

But when I try to replace it:

\t prefix\1suffix \t

It does not work.


Solution

  • You're repeating the capture group; only the last word character will be captured. Place the operator inside of the group construct to quantify the \w token instead of the group.

    Use Ctrl+H to open the Search and Replace, enable Regular Expression if you haven't ..

    Find What: \t(\w+)\t
    Replace With: \tprefix\1suffix\t