Regex partial replacement syntax? Grouping not working

  • I have tried both\ and $ to group the strings I’m trying to match and substitute. This syntax works in other text editors, and on the web in a regex tester. This search does find 2008 but it doesn’t replace it properly. Is there a different syntax I should be using, or is there a setting I am missing?
    String to search for
    String to search in
    Replacement String
    <a href="…/\1/\1.html">\1</a>\2
    <td><a href="…//.html"></a>/td>
    Desired Result
    <td><a href="…/2008/2008.html"></a>/td>

  • I’m using Notepad++ v7.1.1 (64 bit) on a Windows 10 Pro 64 bit computer. brand new user and this is the out-of-the-box vanilla version.

  • For me this work with npp7.7.1 on win7 x64.
    It produce the desired output because of the used regex but it does replace 2008.
    Could you post your debug info, which is available under the last menu item, the ? menu ?

  • I’m baffled. I did the search/replace this time and it WORKED. I had rebooted in the meantime, perhaps something was cached?

  • It works in one file, but not in another. Here’s the debug info:

    Notepad++ v7.7.1 (64-bit)
    Build time : Jun 16 2019 - 21:24:47
    Path : D:\notepad++\notepad++.exe
    Admin mode : OFF
    Local Conf mode : OFF
    OS : Windows 10 (64-bit)

    I also tried copy and paste of the relevant text into a brand new file and that didn’t work either
    Plugins : mimeTools.dll NppConverter.dll

  • @Pam-Rathmell
    which checkboxes are actually checked in the find/replace dialog and are you aware
    that when the caret is after the text to be found that only wrap around checked would start searching from
    the beginning?

  • I ended up using another text editor to make the (massive) changes. But I’d like to know if this is actually a bug?

  • Based on your question, I did some more fiddling around. I had “backward direction” and “wrap-around” checked. With these settings, I got a reliable failure. When I changed it to “forward direction” it succeeded. I believe this is a bug and backward direction does not recognize the grouping.

  • @Pam-Rathmell

    Moving in a backward direction is tricky for regular expression engines. It mostly works okay, but it does strange things often enough that even Notepad++ at one time disabled it (searching ‘up’ when the Search mode was Regular expression). That disabling has mostly gone away now it seems.

    I guess you have stumbled upon one of the odd situations.

    I wanted to see what Pythonscript’s regular expression replacement function would do with your situation, and in trying to get it working I started with a simpler search, and I discovered that attempting to search backwards, even very simply, gives no matches at all. :(

Log in to reply