Repeating the same expression multiple in RegEx search, and replace it only one time – via: Stack Overflow
Posted by jpluimers on 2015/07/29
I’m really really glad that Lucas Trzesniewski has answered this:
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
\1for referencing strings, others use$1and 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.
And my comment:
Thanks a lot for that. I found a bit more information about back references and capture groups in various libraries on regular-expressions.info/replacebackref.html.
on my question:
I’m searching for groups of patterns that look like this:
[httpUrl](httpUrl "httpUrl")and replace them with:
<httpUrl>With a twist: all
httpUrlmust 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).
–jeroen
PS: The question is marked JavaScript as regex is used there very often, so it was easier to attract potential answers.






Leave a comment