Notepad++ regex Replace, using match variables

8

2

In Notepad++, I want to perform a find-and-replace, providing a variable in the 'Replace with' field, which references a match from the 'Find what' field. Any ideas?

I tried supplying (find) foo (\w) bar (replace) foo baz ($1) bar qux. That didn't work.

JellicleCat

Posted 2012-02-07T20:12:17.283

Reputation: 1 721

4Try \1 instead. – EBGreen – 2012-02-07T20:15:35.313

1Easy rep there if someone wants to write up a nice answer. I don't use Notepad++ so I didn't make it an answer. I do however use google and figured the OP would appreciate something that would solve the issue even if it wasn't a proper answer. – EBGreen – 2012-02-07T21:46:39.740

Answers

13

Notepad++ uses standard POSIX regular expressions. As such, backreferences should use the slash instead of the dollar-sign:

Find    : foo (\w) bar
Replace : foo baz (\1) bar qux

Synetech

Posted 2012-02-07T20:12:17.283

Reputation: 63 242

0

I think you need to have a token identifier. So if I modified Synetech's answer, I would change "Find" part to "foo (?'one'\w+) bar"

VJC

Posted 2012-02-07T20:12:17.283

Reputation: 1

1It would help if you can test the solution and provide an answer, Starting an answer as "i think" doesn't show confidence, and you might get down votes – SeanClt – 2016-03-24T17:20:12.543

Fair enough. I was trying to add to the existing answer. – VJC – 2016-03-24T21:09:31.813