Community
    • Login

    [regex] Why unexpected hit?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 85 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
      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
        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
          Shohreh @PeterJones
          last edited by

          @PeterJones Thank you.

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