Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 2 regex matching with >9 back-references

I'm trying to capture several groups within a string and reorder them using a regex. However once I reach greater then 9 back-references, they do not replace as I expected.

Eg: This is a bit of a contrived example, but it should illustrate what's happening.

Input string: abcdefghij
Find What: ^(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)$
Replace With: \10
Expected output: j
Actual output: a0

I also tried:

  Replace With: $10

Instead of \10 or $10 inserting the contents of the tenth grouping parens, it inserts the contents of the first grouping parens follower by "0".

UPDATE:

This does work using $10 in newer versions of Sublime Text, but it is way better to use the ${10} syntax as described below.

like image 708
Karl Wilbur Avatar asked Sep 27 '13 20:09

Karl Wilbur


1 Answers

Use:

${10}

I just tried it and that worked for me.

I also tried using find:

^(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)$

Replace with: $10

And it worked. I'm using v2.0.2 build 2221 however. The same with \10 doesn't work, but works as you described in your question.

It might be worth noting as well that many of the regex engines replace are shifting from the \# format to the $# format so that's maybe why $# is working better for me even without braces.

Though now, if you wanted to replace with the 10th capture followed by a number (e.g. $100) the engine will look for the 100th capture group and for your example, will replace with nothing.

like image 198
Jerry Avatar answered Nov 27 '22 01:11

Jerry