• Login
Community
  • Login

regex, lookbehind error

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 3 Posters 794 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.
  • E
    Eli Grey
    last edited by Eli Grey Feb 1, 2023, 4:49 PM Feb 1, 2023, 4:46 PM

    I tried (?<=\s+) for searching 2 or more empty (allowing tab or spacebar inserted) line but this gives me an error.
    The error message is ‘Find : invalid regular expression’.

    I tested lookbehind and \s+ separately and both work fine. I want to know what is wrong when those two expressions are combined together.

    Actually, even (?<=\s) work fine too, but when I add + or * to the right side of \s to allow multiple whitespaces, the error occurs. Someone help me please.

    P D 2 Replies Last reply Feb 1, 2023, 5:04 PM Reply Quote 1
    • P
      PeterJones @Eli Grey
      last edited by PeterJones Feb 1, 2023, 5:44 PM Feb 1, 2023, 5:04 PM

      @Eli-Grey ,

      Lookbehinds must be of a fixed length. \s+ is not fixed width.

      https://npp-user-manual.org/docs/searching/#assertions

      edit: the manual also suggests a workaround using \K, so instead of (?<=\s+)REALTEXT, use \s+\KREALTEXT

      E 1 Reply Last reply Feb 1, 2023, 6:38 PM Reply Quote 5
      • D
        dinkumoil @Eli Grey
        last edited by Feb 1, 2023, 5:37 PM

        @Eli-Grey

        Additionally to what @PeterJones said, I want to mention that this is a restriction of the boost regular expression engine that Notepad++ uses under the hood. There are a few regular expression engines that don’t have this restriction (see section Important Notes About Lookbehind >> at this site << ), but in Notepad++ we have to live with it.

        E 1 Reply Last reply Feb 1, 2023, 6:40 PM Reply Quote 5
        • E
          Eli Grey @PeterJones
          last edited by Feb 1, 2023, 6:38 PM

          @PeterJones Thank you so much, I understood what I need.

          1 Reply Last reply Reply Quote 0
          • E
            Eli Grey @dinkumoil
            last edited by Feb 1, 2023, 6:40 PM

            @dinkumoil Thank you, actually I’m studying regex with 'Mastering Regex by Jeffrey Friedl and maybe I didn’t consider the differences on those engines.

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