3

For example, I would like to replace a string by the first capture group, with a 1 appended to it.

I would like to do $11 (interpreted as $1 and 1), but this does not work on every flavour.

What should I do instead?

Kenny Lau
  • 457
  • 5
  • 13

1 Answers1

3

The info at the Retina link you provided says:

Under the hood, it uses .NET's regex engine, which means that both the .NET flavour and the ECMAScript flavour are available.

So, if you are using the .NET flavor, use ${1}1 to replace with the first backreference and 1, use ${11} or $11 to replace with the 11th backreference.

If you are using an ECMAScript expression, $11 will be treated this way: if there are fewer than 11 capture groups, but there is 1, $1 will be parsed as the backreference to Group 1 followed with a literal 1; if there are 11 capture groups, it will be a backreference to the 11th group.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563