4

I want to use Notepad++ to find/replace large chunks of code, but a hefty part of it deals with arrays. How can I put a "variable" in Notepad++'s Find/Replace window so that part of it can be saved and not overwritten?

The below example isn't perfect, as it could be converted using two simple find/replace searches, but I'd like to do something to the effect of Find: o[*] and Replace: p*.

Example

Original:

Or(a=o[0]);
Or(a=o[1]);
Or(a=o[2]);
Or(a=o[3]);
Or(a=o[4]);

What I need:

Or(a=p0);
Or(a=p1);
Or(a=p2);
Or(a=p3);
Or(a=p4);

1 Answer 1

4

If you enable the Regular expression radio button, you can use parenthesis to hold values.

Whatever is contained within the first () gets stored in \1, the second in \2 and so on.

Here's a basic illustration of that for your example.

variable replacement in notepad++
The \d matches a digit. [ and ] have to be escaped with \ because they are special characters.

1
  • Brilliant, this is exactly what I need. I haven't quite taken the jump to learn regex yet, but I'm getting there. :) Thank you!
    – vaindil
    Commented Sep 19, 2013 at 0:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .