1

I'm searching for groups of patterns that look like this:

[httpUrl](httpUrl "httpUrl")

and replace them with:

<httpUrl>

With a twist: all httpUrl must result in the same string and non-greedy.

I already got a start using RegExr: matching this pattern in a lazy manner and the twist:

\[(http:\/\/.*?)\]\(\1 "\1"\)

But I have a problem finding the replacement expression as this doesn't work:

<\1>

What am I missing here? (I hope it is soo simple that I will say duh).

Community
  • 1
  • 1
Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154
  • 1
    What language or tool are you using? Your regex is correct, but your replacement string may have to be expressed as `<$1>` for instance depending on the language. – Lucas Trzesniewski Oct 18 '14 at 15:40
  • @LucasTrzesniewski thanks for that. I was testing in [RegExr](http://www.regexr.com/) but wanted to use it in [Notepad++](http://notepad-plus-plus.org/). Just found out RegExr wants `$1` and Notepad++ wants `\1`. Like I wrote: `duh`. Please make that into an answer, and I will accept that. – Jeroen Wiert Pluimers Oct 18 '14 at 15:44
  • 2
    @JeroenWiertPluimers RegExr is designed for javascript only. – Avinash Raj Oct 18 '14 at 15:45

1 Answers1

1

While most regex flavours have roughly a similar syntax for the basic features, there is not a clear standard as to the syntax of the replacement strings. Some tools use \1 for referencing strings, others use $1 and so on.

As you use Notepad++, you should know it uses the boost library for its regex implementation, and it uses the Boost-Extended format string for the replacement pattern.

In particular, the placeholder for the nth capture group is $n.

Lucas Trzesniewski
  • 50,214
  • 11
  • 107
  • 158
  • 1
    Thanks a lot for that. I found a bit more information about back references and capture groups in various libraries on http://www.regular-expressions.info/replacebackref.html – Jeroen Wiert Pluimers Oct 18 '14 at 15:51