Community
    • Login

    [regex] Why unexpected hit?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 512 Views 2 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.
    • S Offline
      Shohreh
      last edited by

      Hello,

      I need to find only lines that begin with three capital letters, so I used the following:

      ^[A-Z]{3}
      

      For some reason, NP++ also finds the line that starts with “Bur”. Why is that?

      I know I can check the “Match Case” option but I shouldn’t have to.

      Thank you.

      eab5d5c0-f50b-4549-96b3-50372026da61-image.png

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP Offline
        PeterJones @Shohreh
        last edited by PeterJones

        @Shohreh said in [regex] Why unexpected hit?:

        I know I can check the “Match Case” option but I shouldn’t have to.

        Yes you should. That checkmark literally tells the regular expression engine whether to do case sensitive or case-insensitive matching. With “match case” off, then U in the regex matches U or u in the text, whether it’s in the regular expression as a literal U or whether it’s in a range like [A-Z].

        If you don’t like clicking a checkbox, you could instead use the regular expression command that forces case sensitivity, specifically (?-i) (“turn off case-insensitive matching”), so your regex could be (?-i)^[A-Z]{3} to force case-sensitive matching.

        But you absolutely, positively must set case sensitivity on via one of those two methods if you want any U in the regex to only match uppercase U and not lowercase u – that’s literally what “case sensitive”/“match case” vs “case insensitive”/“don’t match case” means.

        S 1 Reply Last reply Reply Quote 2
        • S Offline
          Shohreh @PeterJones
          last edited by

          @PeterJones Thank you.

          1 Reply Last reply Reply Quote 0

          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