Notepad2 Regular Expressions

Notepad2 is an excellent lightweight text editor for Windows – but I had some problems figuring out how to use Regular Expressions to find and replace some repetitive HTML code in a web page.

The code looked like a lot of rows and I wanted to put the link text into the title attribute:
<ul>
<li><a href="some url" title="">Swindon</a></li>
</ul>
A standard perl type regular expression would look like:
search: title="">([a-zA-Z]+)<
replace: title="Homes in $1">$1<

In Notepad2, you have to use a backslash for the backreference:
search: title="">([a-zA-Z]+)<
replace: title-"Homes in \1">\1<

This worked great for me, just a pity they couldn’t have stuck with the dollar sign and done it the way most developers are used to coding.

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA - answer the question below to prove you are human *

This site uses Akismet to reduce spam. Learn how your comment data is processed.