Community
    • Login

    Regex: Find whole words that have only uppercase letters in text

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 2 Posters 6.8k 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.
    • rodica FR
      rodica F
      last edited by rodica F

      Je la regarde d'un air évocateur, AVEC des yeux dont elle ne se rend PAS compte non plus.

      I must find only the whole words that have only uppercase letters in text.

      OUTPUT:

      AVEC, PAS

      Can I use regex?

      Terry RT 1 Reply Last reply Reply Quote 0
      • Terry RT
        Terry R @rodica F
        last edited by Terry R

        @rodica-F said in Regex: Find whole words that have only uppercase letters in text:

        Can I use regex?

        Yes, I have created a regex which works. It’s probably not the prettiest but appears to select ONLY what you want.

        I used the “Mark” function and entered:
        Find What:(?-i)[A-Z]+(?![a-z])

        So the -i means the regex is case sensitive (officially it says not case insensitive). The lookahead says that when we have grabbed ALL the uppercase characters there aren’t any remaining lowercase characters left in the word.

        See if that helps.

        Terry

        Terry RT 1 Reply Last reply Reply Quote 1
        • Terry RT
          Terry R @Terry R
          last edited by

          @Terry-R said in Regex: Find whole words that have only uppercase letters in text:

          It’s probably not the prettiest but appears to select ONLY what you want.

          I did some more testing and can see it will fail in some situations. See my image below for an example. I’m english speaking and unforunately accented characters are foreign to me. So it will likely fall to another seasoned forum member ( @guy038 generally comes thru with the goods) to provide a better solution.

          097d1ad0-4866-4f0c-9668-ef191c5a7ddd-image.png

          Terry

          rodica FR Terry RT 2 Replies Last reply Reply Quote 2
          • rodica FR
            rodica F @Terry R
            last edited by

            @Terry-R thank you

            rodica FR 1 Reply Last reply Reply Quote 0
            • rodica FR
              rodica F @rodica F
              last edited by rodica F

              Also, anothe regex can be this one (find whole words that have only uppercase)

              Find: \b[A-Z]\w+[A-Z]\b
              (use Match Case)

              or simple"

              FIND: (?-i)\b[A-Z]\w+[A-Z]\b

              1 Reply Last reply Reply Quote 0
              • Terry RT
                Terry R @Terry R
                last edited by

                @Terry-R said in Regex: Find whole words that have only uppercase letters in text:

                I did some more testing and can see it will fail in some situations.

                I have had more time to consider how it might work and also to look at “classes”. This next solution is I think working correctly and will also allow for words with a ' in them such as DON’T.
                Find What:(?-i)\b[[:upper:]](?:[[:upper:]]|')+\b

                I had to start it with a look for an upper character, otherwise it would select just a ' by itself. You may also want to extend to include a - if you need to. If adding a - then it becomes (?-i)\b[[:upper:]](?:[[:upper:]]|'|-)+\b.

                Terry

                492d7dc6-504f-485b-a76b-1d51461b5f1f-image.png

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors