Help with regex: bug?
-
I feel like something is going wrong with my regex search in notepad++. It looks like a bug but I want to know if it’s a problem in my query. My query is highlighting something it is not supposed to.
My query:\b([A-Z]([A-Za-z]*)\.[a-zA-Z_-][a-zA-Z_-]*)
essentially, it should start with capital letter, then have any letters after it, a dot, and then any function call name.
My query is highlighting an instance that doesn’t start with a capital letter and I don’t know how to stop it.
Wrongly highlighting:session.issued
in
if session.issued==max_issued:
This happens with EnhanceAnyLexer and N++ search. Checking on online regex testers this isn’t the case: see regexr.com/7nu78
See screenshots too.
(I know that I can modify my query for [^=] to temporarily fix this, but that doesn’t solve the issue of unexpected regex behaviour.)
My version: 8.5.8
Would appreciate help here. Thanks!
-
@Monospace-V
By default the regex engine is case insensitive meaning a-z and A-Z are the same. You need to use a modifier before the expression to make it see capitals only when using A-Z. Look at (?-i). Search posts on this forum as there are lots of expressions using this where the case is important.Sorry I’m typing this on a phone so hard to find and post links
Terry
-
@Terry-R found. Fixed. Thanks for the info; it did not occur that a language like regex with separate options for uppercase and lowercase could have any case insensitivity enabled by default.
-
By default the regex engine is case insensitive meaning a-z and A-Z are the same.
it did not occur (to me) that a language like regex with separate options for uppercase and lowercase could have any case insensitivity enabled by default.
It actually isn’t case sensitive by default. But because the Notepad++ user interface to searching has a Match case checkbox, the state of that become part of the operation. If uncheckmarked when the operation starts, then, well…
For regex purists, perhaps always starting your regex with
(?-i)
– which overrides the state of the Match case checkbox – is the way to go.