Community
    • Login

    Regex - Find Consecutive Uppercase Characters

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    regex
    7 Posts 4 Posters 1.4k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Sylvester BullittS Offline
      Sylvester Bullitt
      last edited by

      I’m trying to create a regex to find consecutive upper case characters. My test input strings:

      No Consecutive Uppercase Characters
      CoNSecutive Uppercase Characters

      My regex attempts (these all give false positives):

      [:upper:]{2}
      [[:upper:]]{2}
      ([:upper:]){2}

      What am I doing wrong?

      Alan KilbornA CoisesC 2 Replies Last reply Reply Quote 0
      • Alan KilbornA Offline
        Alan Kilborn @Sylvester Bullitt
        last edited by

        @Sylvester-Bullitt

        I’d try: (?-i)\u\u

        Sylvester BullittS 1 Reply Last reply Reply Quote 2
        • CoisesC Offline
          Coises @Sylvester Bullitt
          last edited by Coises

          @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 Characters

          My 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.

          mkupperM 1 Reply Last reply Reply Quote 2
          • mkupperM Offline
            mkupper @Coises
            last edited by

            @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.

            CoisesC 1 Reply Last reply Reply Quote 2
            • Sylvester BullittS Offline
              Sylvester Bullitt @Alan Kilborn
              last edited by

              @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!

              1 Reply Last reply Reply Quote 1
              • CoisesC Offline
                Coises @mkupper
                last edited by

                @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).

                Alan KilbornA 1 Reply Last reply Reply Quote 1
                • Alan KilbornA Offline
                  Alan Kilborn @Coises
                  last edited by

                  @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.

                  1 Reply Last reply Reply Quote 2

                  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
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors