How do I group regular expressions past the 9th backreference?

meanbunny picture meanbunny · Jun 6, 2012 · Viewed 12.5k times · Source

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?

Answer

BunjiquoBianco picture BunjiquoBianco · Jun 6, 2012

You can simply reference groups > 9 in the same way as those < 10

i.e $10 is the tenth group.

For (naive) example:

String:

abcdefghijklmnopqrstuvwxyz

Regex find:

(?:a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)(o)(p)

Replace:

$10

Result:

kqrstuvwxyz

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:

"What if you want to replace with the 1st group followed by the character '0'?"

To do this change the replace to:

$1\x30

Which is replacing with group 1 and the hex character 30 - which is a 0 in ascii.