• Login
Community
  • Login

Regex - Find Consecutive Uppercase Characters

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
regex
7 Posts 4 Posters 773 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.
  • S
    Sylvester Bullitt
    last edited by Oct 14, 2023, 5:06 PM

    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?

    A C 2 Replies Last reply Oct 14, 2023, 5:20 PM Reply Quote 0
    • A
      Alan Kilborn @Sylvester Bullitt
      last edited by Oct 14, 2023, 5:20 PM

      @Sylvester-Bullitt

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

      S 1 Reply Last reply Oct 14, 2023, 9:26 PM Reply Quote 2
      • C
        Coises @Sylvester Bullitt
        last edited by Coises Oct 14, 2023, 5:38 PM Oct 14, 2023, 5:37 PM

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

        M 1 Reply Last reply Oct 14, 2023, 6:04 PM Reply Quote 2
        • M
          mkupper @Coises
          last edited by Oct 14, 2023, 6:04 PM

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

          C 1 Reply Last reply Oct 14, 2023, 9:54 PM Reply Quote 2
          • S
            Sylvester Bullitt @Alan Kilborn
            last edited by Oct 14, 2023, 9:26 PM

            @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
            • C
              Coises @mkupper
              last edited by Oct 14, 2023, 9:54 PM

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

              A 1 Reply Last reply Oct 15, 2023, 12:15 AM Reply Quote 1
              • A
                Alan Kilborn @Coises
                last edited by Oct 15, 2023, 12:15 AM

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