Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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);
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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++![][1]
The \d matches a digit. [ and ] have to be escaped with \ because they are special characters.

share|improve this answer
    
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 Sep 19 '13 at 0:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.