Community
    • Login

    Regex - Find Consecutive Uppercase Characters

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    regex
    7 Posts 4 Posters 756 Views
    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
      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
        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
          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
            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
              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
                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
                  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
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors