Ok so I am trying to group past the 9th backreference in notepad++. The wiki says that I can use group naming to go past the 9th reference. However, I can't seem to get the syntax right to do the match. I am starting off with just two groups to make it simple.
Sample Data
1000,1000
Regex.
(?'a'[0-9]*),([0-9]*)
According to the docs I need to do the following.
(?<some name>...), (?'some name'...),(?(some name)...)
Names this group some name.
However, the result is that it can't find my text. Any suggestions?
OK, matching is no problem, your example matches for me in the current Notepad++. This is an important point. To use PCRE regex in Notepad++, you need a Version >= 6.0.
The other point is, where do you want to use the backreference? I can use named backreferences without problems within the regex, but not in the replacement string.
means
will match
But I don't know a way to use named groups or groups > 9 in the replacement string.
Do you really need more than 9 backreferences in the replacement string? If you just need more than 9 groups, but not all of them in the replacement, then make the groups you don't need to reuse non-capturing groups, by adding a
?:
at the start of the group.You can simply reference groups > 9 in the same way as those < 10
i.e $10 is the tenth group.
For (naive) example:
String:
Regex find:
Replace:
Result:
My test was performed in Notepad++ v6.1.2 and gave the result I expected.
Update: This still works as of v7.5.6
SarcasticSully resurrected this to ask the question:
To do this change the replace to:
Which is replacing with group 1 and the hex character
30
- which is a0
in ascii.A very belated answer to help others who land here from Google (as I did). Named backreferences in notepad++ substitutions look like this:
$+{name}
. For whatever reason.There's a deviation from standard regex gotcha here, though... named backreferences are also given numbers. In standard regex, if you have
(.*)(?<name> & )(.*)
, you'd replace with$1${name}$2
to get the exact same line you started with. In notepad++, you would have to use$1$+{name}$3
.Example: I needed to clean up a Visual Studio .sln file for mismatched configurations. The text I needed to replace looked like this:
My search RegEx:
My replacement RegEx:
The result:
Hope this helps someone.