Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So, Notepad++ got updated to v6.0. One of their new features is PCRE (Perl Compatible Regular Expressions).

I tried to use this new feature to find and replace things in a file. I tried the regular expression:


and it yelled at me, saying "Invalid regular expression".

I tested this regex in other programs (like my main IDE, Geany), and it worked fine.

Why does this not work in Notepad++ 6.0?

share|improve this question
What do you expect your regexp to do? – Daniel Andersson Apr 6 '12 at 14:54
I'd expect it to match strings like this: {$first_name}, {$street_address}. Which it does: – Rocket Hazmat Apr 6 '12 at 14:55
up vote 3 down vote accepted

You have to escape the {} like so:


I assume Geany and don't use PCRE (or they use it differently). Please note that {} are usually used to denote quantifiers.

Without having checked the source, I can only assume that Notepad++ tries to be too smart before passing the regular expression to the PCRE library. If I run the following code in PHP:

echo preg_match( '{\$([a-zA-Z_]*)}', '{$something}' );

It prints 1 right away. No need to escape anything.

Sorry that I can't explain it :(

share|improve this answer
I'm a bit confused myself, to be honest. – Oliver Salzburg Apr 6 '12 at 15:19
In PHP, you need to escape the $, but not the {}. – Rocket Hazmat Apr 6 '12 at 15:30
@Rocket I think you only need to escape $ if you use double-quotes " instead of single-quotes '. – Oliver Salzburg Apr 6 '12 at 15:55
But, $ means "end of string" in regex. You'd need to escape it double quotes because of PHP's variable interpolation. – Rocket Hazmat Apr 6 '12 at 15:56
Sorry, I got confused. You're obviously right. Thanks for noticing. – Oliver Salzburg Apr 6 '12 at 15:57

You must log in to answer this question.

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