• Login
Community
  • Login

Help with regex: bug?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
4 Posts 3 Posters 299 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.
  • M
    Monospace-V
    last edited by Monospace-V Nov 27, 2023, 8:18 AM Nov 27, 2023, 8:18 AM

    I feel like something is going wrong with my regex search in notepad++. It looks like a bug but I want to know if it’s a problem in my query. My query is highlighting something it is not supposed to.
    My query:

    \b([A-Z]([A-Za-z]*)\.[a-zA-Z_-][a-zA-Z_-]*)
    

    essentially, it should start with capital letter, then have any letters after it, a dot, and then any function call name.
    My query is highlighting an instance that doesn’t start with a capital letter and I don’t know how to stop it.
    Wrongly highlighting:

    session.issued
    

    in

    if session.issued==max_issued:
    

    This happens with EnhanceAnyLexer and N++ search. Checking on online regex testers this isn’t the case: see regexr.com/7nu78
    See screenshots too.
    (I know that I can modify my query for [^=] to temporarily fix this, but that doesn’t solve the issue of unexpected regex behaviour.)
    My version: 8.5.8
    Would appreciate help here. Thanks!

    4f42c346-aca8-41d0-8942-6d23fa49a490-image.png
    20e0e8c4-49bf-41e6-979d-a1802d7d69ed-image.png

    T 1 Reply Last reply Nov 27, 2023, 8:51 AM Reply Quote 0
    • T
      Terry R @Monospace-V
      last edited by Nov 27, 2023, 8:51 AM

      @Monospace-V
      By default the regex engine is case insensitive meaning a-z and A-Z are the same. You need to use a modifier before the expression to make it see capitals only when using A-Z. Look at (?-i). Search posts on this forum as there are lots of expressions using this where the case is important.

      Sorry I’m typing this on a phone so hard to find and post links

      Terry

      M 1 Reply Last reply Nov 27, 2023, 8:59 AM Reply Quote 2
      • M
        Monospace-V @Terry R
        last edited by Nov 27, 2023, 8:59 AM

        @Terry-R found. Fixed. Thanks for the info; it did not occur that a language like regex with separate options for uppercase and lowercase could have any case insensitivity enabled by default.

        A 1 Reply Last reply Nov 27, 2023, 12:42 PM Reply Quote 2
        • A
          Alan Kilborn @Monospace-V
          last edited by Nov 27, 2023, 12:42 PM

          By default the regex engine is case insensitive meaning a-z and A-Z are the same.

          it did not occur (to me) that a language like regex with separate options for uppercase and lowercase could have any case insensitivity enabled by default.

          It actually isn’t case sensitive by default. But because the Notepad++ user interface to searching has a Match case checkbox, the state of that become part of the operation. If uncheckmarked when the operation starts, then, well…

          For regex purists, perhaps always starting your regex with (?-i) – which overrides the state of the Match case checkbox – is the way to go.

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