• Login
Community
  • Login

Negative lookbehind regular expression not working on Notepad++

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
43 Posts 6 Posters 6.4k 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.
  • D
    dr ramaanand @dr ramaanand
    last edited by dr ramaanand Apr 22, 2025, 4:31 PM Apr 22, 2025, 4:25 PM

    @PeterJones You may want to study what is mentioned at https://www.rexegg.com/regex-lookarounds.php to understand how to use your method of regular expression for multiple negative look behinds. This is the specific regular expression I believe can help: (?<=(?<!(?<!X)_)_)\d+

    P M 2 Replies Last reply Apr 22, 2025, 4:35 PM Reply Quote 0
    • P
      PeterJones @dr ramaanand
      last edited by PeterJones Apr 22, 2025, 4:38 PM Apr 22, 2025, 4:35 PM

      @dr-ramaanand said in Negative lookbehind regular expression not working on Notepad++:

      @PeterJones You may want to study what is mentioned at https://www.rexegg.com/regex-lookarounds.php to understand how to use your method of regular expression for multiple negative look behinds

      Or, I may not.

      As is obvious from this post, I know how to use multiple lookaheads to do the extra logic, and have for years.

      But, as I said, “I really don’t like doing super-complicated single-run regular expressions when a multi-step that’s easier to understand would work.” And trying to rework the multiple conditions into multiple negative lookaheads buried before a \K to mimic a variable-width lookbehind moves it from the “this is reasonable and practical” world to the world of “why don’t you just do it with a simple three-step process, instead of confusing yourself and making other people write one complicated regex to do a job that’s easy if you break it into pieces”.

      @guy038 is able to do those super-fancy regex, and appears to enjoy it, so I let him. But I personally see no need for making a single regex that complex, and will not be using it for myself, nor do I think it’s necessarily the right solution for someone who comes here asking for regex help, since it’s not likely to continue to work when they change their parameters slightly. If @guy038 wants to share such solutions, in the hopes that eventually that person being helped will be able to do more for themselves, great; but I just want a practical solution that’s “good enough”.

      1 Reply Last reply Reply Quote 2
      • M
        mpheath @dr ramaanand
        last edited by mpheath Apr 22, 2025, 6:58 PM Apr 22, 2025, 6:16 PM

        @dr-ramaanand said in Negative lookbehind regular expression not working on Notepad++:

        @PeterJones You may want to study what is mentioned at https://www.rexegg.com/regex-lookarounds.php to understand how to use your method of regular expression for multiple negative look behinds. This is the specific regular expression I believe can help: (?<=(?<!(?<!X)_)_)\d+

        Please explain why as I am not a believer.

        To be more explicit in detail, you have an issue and now you consider nested within nested within nested regular expression is a solution to your problem?

        1 Reply Last reply Reply Quote 2
        • P
          PeterJones @guy038
          last edited by Apr 22, 2025, 7:31 PM

          @guy038 said in Negative lookbehind regular expression not working on Notepad++:

          you could mainly use the general template, below :

          @guy038 , that’s an awesome template.

          I highly encourage you to write up a short blog post about it, and then link to that new post from the Generic Regex Formula FAQ, because I think that’s a formula that could end up being useful.

          (I would just link to your post in here, but the focus is this particular example, which I think would be too complicated for most readers to understand. Doing a simpler example in the blog would be useful, I think, to help people translate your “template” into a real regex.)

          D 1 Reply Last reply Apr 22, 2025, 9:21 PM Reply Quote 2
          • D
            dr ramaanand @PeterJones
            last edited by dr ramaanand Apr 22, 2025, 11:36 PM Apr 22, 2025, 9:21 PM

            @PeterJones I have understood what @guy038 is trying to convey (and I have been using it). A template would be useful and this is an example: (xyz)(*SKIP)(*F)|(z) is like a negative look behind which skips finding any z if it is preceded by y or x (the order of the x and y need not be the same) but finds all other occurrences of z - post no.16 shows how he used it for the block I typed for testing at the top of this thread

            I would prefer a template like this:-

            (String1|String2)(MAIN Regex Search)(*SKIP)(*F)|(MAIN Regex Search)
                                                           |
            <------------- This I do NOT want ------------><- This I DO want ->
            
            D 1 Reply Last reply Apr 23, 2025, 6:13 AM Reply Quote 0
            • D
              dr ramaanand @dr ramaanand
              last edited by dr ramaanand Apr 23, 2025, 10:00 AM Apr 23, 2025, 6:13 AM

              @PeterJones We can add another line below the above RegEx explanation like this (to explain it better):-

              <------------- What I want to SKIP ------------><- What I want to MATCH ->
              
              D 1 Reply Last reply Apr 23, 2025, 10:41 AM Reply Quote 1
              • D
                dr ramaanand @dr ramaanand
                last edited by dr ramaanand Apr 23, 2025, 10:47 AM Apr 23, 2025, 10:41 AM

                @PeterJones The wonderful thing about the (*SKIP)(*F) method is that it can be used for negative look aheads also like this:-

                (MAIN Regex Search)(String1|String2)(*SKIP)(*F)|(MAIN Regex Search)
                                                               |
                <------------- What I want to SKIP ------------><-What I want to MATCH->
                
                P 1 Reply Last reply Apr 23, 2025, 1:01 PM Reply Quote 0
                • P
                  PeterJones @dr ramaanand
                  last edited by Apr 23, 2025, 1:01 PM

                  @dr-ramaanand said in Negative lookbehind regular expression not working on Notepad++:

                  The wonderful thing about the (*SKIP)(*F) method is that it can be used for negative look aheads also like this

                  But pointless, because lookaheads (negative or positive) can have variable width, so if you want a lookahead, just use a lookahead.

                  D 1 Reply Last reply Apr 23, 2025, 1:14 PM Reply Quote 2
                  • D
                    dr ramaanand @PeterJones
                    last edited by Apr 23, 2025, 1:14 PM

                    @PeterJones The (*SKIP)(*F) method can be of variable width but it can be used only for negative look aheads and negative look behinds

                    A 1 Reply Last reply Apr 23, 2025, 1:56 PM Reply Quote 0
                    • A
                      Alan Kilborn @dr ramaanand
                      last edited by Apr 23, 2025, 1:56 PM

                      @dr-ramaanand

                      Peter’s last point (which you missed) was that lookaheads are best done with native regex syntax, because it is more obvious that way.

                      And he probably would have confused you less if he had left out (negative or positive) from his sentence; doing that doesn’t change the meaning.

                      1 Reply Last reply Reply Quote 3
                      • G
                        guy038
                        last edited by guy038 Apr 24, 2025, 10:38 AM Apr 24, 2025, 10:37 AM

                        Hello, @peterjones and All,

                        OK. I going to prepare a blog post regarding the (*SKIP)(*F) feature !

                        However, be patient because I’ll try, first :

                        • To find out some other pertinent examples from various regex sites

                        • To propose alternatives to the (*SKIP)(*F) syntax when it’s possible !

                        BR

                        guy038

                        D 1 Reply Last reply Apr 24, 2025, 12:22 PM Reply Quote 3
                        • D
                          dr ramaanand @guy038
                          last edited by dr ramaanand Apr 24, 2025, 1:20 PM Apr 24, 2025, 12:22 PM

                          @guy038 please create the blog to show how to use the (*SKIP)(*FAIL) regular expression, not an alternative to it. @PeterJones may be able to create an alternative to it. If @PeterJones wants to still use his method for what I have typed as my block for testing, he can do it in 2 parts; first using the regular expression, (<span\b[^>]*?color\s*:\s*black[^>]*>\s*|<p\b[^>]*?color\s*:\s*black[^>]*>\s*<span\b[^>]*>\s*)\K(<code\s*style="background-color:\s*transparent;">) in the find field and a unique string (say for example, a unique name like, “Czeslawski”) in the replace field, he can replace the <code\s*style="background-color:\s*transparent;"> with that unique string. Then he can do what is needed to the other strings of <code\s*style="background-color:\s*transparent;"> and then again replace the unique string (“Czeslawski” in this case) with <code\s*style="background-color:\s*transparent;">. If it is something simple, this example should be sufficient: https://stackoverflow.com/questions/17286667/regular-expression-using-negative-lookbehind-not-working-in-notepad

                          1 Reply Last reply Reply Quote 0
                          • G
                            guy038
                            last edited by Apr 24, 2025, 1:51 PM

                            Hello, @dr-ramaanand,

                            When I said :

                            To propose alternatives to the (*SKIP)(*F) syntax when it’s possible !

                            I’m not talking about a work-around, using a several-steps regex, but, indeed, other direct regexes, without the (*SKIP)(*F) syntax, which are, sometimes, even shorter !

                            You’ll understand what I mean., sooner !

                            Best Regards,

                            guy038

                            D 1 Reply Last reply Apr 24, 2025, 4:50 PM Reply Quote 1
                            • D
                              dr ramaanand @guy038
                              last edited by Apr 24, 2025, 4:50 PM

                              @guy038 I will understand it only after you post that regular expression (RegEx) here

                              D 1 Reply Last reply Apr 26, 2025, 9:50 AM Reply Quote 0
                              • D
                                dr ramaanand @dr ramaanand
                                last edited by Apr 26, 2025, 9:50 AM

                                This post is deleted!
                                1 Reply Last reply Reply Quote 0
                                • G
                                  guy038
                                  last edited by Apr 26, 2025, 1:20 PM

                                  Hello, @peterjones and All,

                                  Peter, Done ! Refer to :

                                  https://community.notepad-plus-plus.org/topic/26812/generic-regex-how-to-use-the-couple-of-backtracking-control-verbs-skip-fail-or-skip-f-in-regexes

                                  I also added a link to this post in your FAQ: Generic Regular Expression (regex) Formulas post.

                                  Best Regards,

                                  guy038

                                  D 1 Reply Last reply Apr 26, 2025, 1:57 PM Reply Quote 3
                                  • D
                                    dr ramaanand @guy038
                                    last edited by dr ramaanand Apr 26, 2025, 5:23 PM Apr 26, 2025, 1:57 PM

                                    @guy038 So, if you have an alternative method to the (*SKIP)(*FAIL) method for the block posted right at the top of this thread for testing to match the same string you posted in post#16 above, please post it here

                                    D 1 Reply Last reply Apr 27, 2025, 10:11 AM Reply Quote 0
                                    • D
                                      dr ramaanand @dr ramaanand
                                      last edited by dr ramaanand Apr 27, 2025, 11:55 AM Apr 27, 2025, 10:11 AM

                                      @guy038 you can use the idea mentioned at www.drregex.com/2019/02/variable-length-lookbehinds-actually.html?m=1 if you please, for the above RegEx. @PeterJones can include that formula in the Notepad++ manual also, if he pleases.

                                      A 1 Reply Last reply Apr 27, 2025, 11:25 AM Reply Quote 0
                                      • A
                                        Alan Kilborn @dr ramaanand
                                        last edited by Alan Kilborn Apr 27, 2025, 11:33 AM Apr 27, 2025, 11:25 AM

                                        @dr-ramaanand said:

                                        www.drregex.com/2019/02/variable-length-lookbehinds-actually.html?m=1

                                        Doesn’t appear to be a valid link, in fact, it seems to point back to the N++ Community site??

                                        THIS is probably the correct link.

                                        D 1 Reply Last reply Apr 27, 2025, 12:15 PM Reply Quote 1
                                        • D
                                          dr ramaanand @Alan Kilborn
                                          last edited by dr ramaanand Apr 27, 2025, 12:21 PM Apr 27, 2025, 12:15 PM

                                          @guy038 The answer by User Doqnach mentioned at https://stackoverflow.com/questions/25563891/variable-length-look-behind can be used as an example.

                                          A 1 Reply Last reply Apr 27, 2025, 12:29 PM Reply Quote 0
                                          27 out of 43
                                          • First post
                                            27/43
                                            Last post
                                          The Community of users of the Notepad++ text editor.
                                          Powered by NodeBB | Contributors