There are a couple of problems with this regex.
Firstly, the '\'
character is “magic” in a regular expression; it tells the regex that the character that follows it should be interpreted specially. \2
and \3
match the text previously captured in the search by wrapping text in brackets (your search only has one set of brackets, so only \1
would be valid here). Also, \s
means “match a single white space character such as a space, tab, newline, etc”.
Since your search doesn’t capture 3 different sets of text with brackets and there is no white space character in the result, it doesn’t match.
In order to just say "I want to match a '\'
" character, you need to quote it to tell the regex engine it’s not special. That would make your regex:
global.test_([a-z]) = 1\\2\\3\\sample_a.xxx
However, based on your sample text, this will only match the first line. This is because the same lower case letter appears in the match on both sides of the equal sign (test_a
= sample_a
and so on), but the search text always has an a
at the end on the right hand side, and only the first line ends that way.
This is where the capture group comes into play. The lower case letter on the left side of the =
character is “captured” by the brackets.
To match every such like, you can use the special \1
construct to match whatever was captured on the left, making your regex (notice only a single backslash on that \1
in this case):
global.test_([a-z]) = 1\\2\\3\\sample_\1.xxx
With all that said, if your intention is actually to throw away everything to the right of the =
in your replacement (including the =
itself), this regex is shorter and sweeter:
global.test_([a-z]).*
The .
means “match any character” and the *
means “match the thing that comes before me 0 or more times”, so together they match the entire rest of the line.