Regex - Find Consecutive Uppercase Characters
-
I’m trying to create a regex to find consecutive upper case characters. My test input strings:
No Consecutive Uppercase Characters
CoNSecutive Uppercase CharactersMy regex attempts (these all give false positives):
[:upper:]{2}
[[:upper:]]{2}
([:upper:]){2}What am I doing wrong?
-
I’d try:
(?-i)\u\u -
@Sylvester-Bullitt said in Regex - Find Consecutive Uppercase Characters:
I’m trying to create a regex to find consecutive upper case characters. My test input strings:
No Consecutive Uppercase Characters
CoNSecutive Uppercase CharactersMy regex attempts (these all give false positives):
[:upper:]{2}
[[:upper:]]{2}
([:upper:]){2}What am I doing wrong?
Most likely you neglected to check Match case in the Find dialog.
Aside from that, your second try,
[[:upper:]]{2}, is correct. The others won’t do what you expect. -
@Coises said in Regex - Find Consecutive Uppercase Characters:
Aside from that, your second try, [[:upper:]]{2}, is correct. The others won’t do what you expect.
Sadly, that does not work unless you also enable case-sensitive mode using
(?-i)[[:upper:]]{2}You would think that searching for
\u,\l,[[:upper:]]or[[:lower:]]would clue the regular expression engine into that the user desires a case sensitive match. I assume the deep thinkers behind regular expressions have a good reason for why those are not automatically case-sensitive matches without extra work. -
@Alan-Kilborn You’re right. That did the trick. Seems counter-intuitive, as if we have to tell NPP about case twice. But I can’t argue with success. Thanks for the assist!
-
@mkupper said in Regex - Find Consecutive Uppercase Characters:
Sadly, that does not work unless you also enable case-sensitive mode using (?-i)[[:upper:]]{2}
That’s strange. I double-checked again after reading your message: with Match case checked I definitely get correct results using
[[:upper:]]{2}without the(?-i)prefix.Tested on Notepad++ v8.5.7 (64-bit) and v8.4.8 (32-bit).
-
@Coises said in Regex - Find Consecutive Uppercase Characters:
That’s strange. I double-checked again after reading your message: with Match case checked I definitely get correct results using [[:upper:]]{2} without the (?-i) prefix.
I’d guess that @mkupper didn’t notice the “Most likely you neglected to check Match case in the Find dialog” comment above your regex in your previous post.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login