Matching regular expression Sublime Text 2 s> 9 backlinks

I am trying to grab several groups inside a string and reorder them using regex. However, as soon as I reach more than 9 backlinks, they do not replace as I expected.

For example: This is a slightly contrived example, but it should illustrate what is 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 pairs, it inserts the contents of the first follower of the group parsers to "0".

UPDATE:

This works using $10 in newer versions of Sublime Text, but it's better to use the ${10} syntax, as described below.

+6
source share
2 answers

Using:

 ${10} 

I just tried it and it worked for me.

I also tried using find:

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

Replace with: $10

And it worked. However, I am using v2.0.2 build 2221. The same with \10 does not work, but it works as you described in your question.

It may be worth noting that many of the regex engines change from \# to $# , so that’s probably why $# works better for me even without braces.

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

+8
source

You need to put braces around

 ${10} 

Make this a habit!

This becomes even more useful if you really want to add $1 with number 0 . Then you may need ${1}0

+4
source

Source: https://habr.com/ru/post/954811/


All Articles