[regex] Why unexpected hit?
-
Hello,
I need to find only lines that begin with three capital letters, so I used the following:
^[A-Z]{3}
For some reason, NP++ also finds the line that starts with “Bur”. Why is that?
I know I can check the “Match Case” option but I shouldn’t have to.
Thank you.
-
@Shohreh said in [regex] Why unexpected hit?:
I know I can check the “Match Case” option but I shouldn’t have to.
Yes you should. That checkmark literally tells the regular expression engine whether to do case sensitive or case-insensitive matching. With “match case” off, then
U
in the regex matchesU
oru
in the text, whether it’s in the regular expression as a literalU
or whether it’s in a range like[A-Z]
.If you don’t like clicking a checkbox, you could instead use the regular expression command that forces case sensitivity, specifically
(?-i)
(“turn off case-insensitive matching”), so your regex could be(?-i)^[A-Z]{3}
to force case-sensitive matching.But you absolutely, positively must set case sensitivity on via one of those two methods if you want any
U
in the regex to only match uppercaseU
and not lowercaseu
– that’s literally what “case sensitive”/“match case” vs “case insensitive”/“don’t match case” means. -
@PeterJones Thank you.