Regular expressions is really nifty to use when you got a chunk of data and need to extract or change certain parts of it. I’ve used it before in Notepad2 to replace mostly with empty strings but this time I wanted a little bit more. I needed backreferences but had no idea how to do it and the regular $1 didn’t work at all. Nor, could Notepad2 find my groups either.

This regex would return nothing:

Search string: <(.*)>(.*)</.*>
Replace string: <item id="$1">$2</item>

After reading some blog posts and finally looking into the docs I found out that regex groups needs to be escaped, and backreferences was used by replacing $1 with \1.

So the query above would instead look like:

Search string: <\(.*\)>\(.*\)</.*>
Replace string: <item id="\1">\2</item>

Boom! Now it works like a charm! 🙂

NOTE: Regex in Notepad2 only works on single lines, if you need multi-lines you need to fire up another program such as i.e. RegexBuddy.