Community
    • 登入

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

    已排程 已置頂 已鎖定 已移動 Help wanted · · · – – – · · ·
    5 貼文 4 Posters 3.3k 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • Joe FurlongJ
      Joe Furlong
      最後由 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 條回覆 最後回覆 回覆 引用 1
      • guy038G
        guy038
        最後由 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 條回覆 最後回覆 回覆 引用 2
        • Scott SumnerS
          Scott Sumner
          最後由 編輯

          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 條回覆 最後回覆 回覆 引用 0
          • Joe FurlongJ
            Joe Furlong
            最後由 編輯

            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 條回覆 最後回覆 回覆 引用 0
            • dailD
              dail
              最後由 編輯

              Title updated.

              1 條回覆 最後回覆 回覆 引用 1
              • 第一個貼文
                最後的貼文
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors