Regex in Notepad++ 6
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:
{\$([a-zA-Z_]*)}
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?
Solution 1:
You have to escape the {}
like so:
\{\$([a-zA-Z_]*)\}
I assume Geany and rubular.com 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 :(