Community
    • Login

    RegEx Replace button doesn't work as expected with a look-behind.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 4 Posters 3.6k 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.
    • Joe FurlongJ Offline
      Joe Furlong
      last edited by dail

      Today I found that when using the “Replace” button when using a positive lookahead and a capture group Notepad++ doesn’t replace anything. It only iterates through like “Find Next”.

      For example in the Changelog for the latest version If I wanted to remove the new lines between all the plugin versions with a regex.
      Excerpt from Changelog to remove newline characters:
      "

      1. NppExport v0.2.8
      2. Plugin Manager 1.3.5
      3. Converter 3.0
      4. Mime Tool 1.9
        "
        use the regex: (?<=.\d)(\r\n)
        Set the replace with as a space or comma.

      If I press “Replace All” the replace works on all 4 lines as expected. But, if I just try the “Replace” no replacements are made.
      If I don’t use a lookahead the “Replace” button works as expected.

      Is there a reason for this behavior?

      1 Reply Last reply Reply Quote 1
      • guy038G Offline
        guy038
        last edited by guy038

        Hello Joe,

        The behaviour of the N++ regex engine is quite bugged, if your regex contains “backward” assertions, as \A or look-behind, as (?<=xxx) and also if you use the \K syntax . In that case, the step by step replacement, with the Replace button, will NEVER work :-(( Therefore, you must use the Replace All button, exclusively !

        Just note that “forward” assertions, as \z and positive or negative look-ahead, as (?=xxxx) or (?!xxxx), work fine and that the use of the Replace button is effective !


        BTW, many thanks to you for your regex, as a reply to greg marshall. Refer to the address, below :

        https://notepad-plus-plus.org/community/topic/12362/duplicate-rows-according-to-whats-in-a-column/4

        Indeed, it helped me to find out a general regex, to get all the work done, in one go !

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 2
        • Scott SumnerS Offline
          Scott Sumner
          last edited by

          Reading this posting, it strikes me that perhaps the title should be

          “RegEx Replace button doesn’t work as expected with a look-behind.”

          rather than

          “RegEx Replace button doesn’t work as expected with a positive lookahead.”

          1 Reply Last reply Reply Quote 0
          • Joe FurlongJ Offline
            Joe Furlong
            last edited by

            Scott,
            You are correct on the title of the post. I posted too late, and did mean the look-behind as you mentioned. When i tried to edit the post, I was given an error stating it can only be edited withing 180 seconds. I’ll poke around a bit, and see if I have any luck to correct the title.

            Guy038 thanks for the response. I did notice that other regex did appear to work. Was curious why the look behind didn’t work.

            Thanks again.

            Joe–

            1 Reply Last reply Reply Quote 0
            • dailD Offline
              dail
              last edited by

              Title updated.

              1 Reply Last reply Reply Quote 1

              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