Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Regex partial replacement syntax? Grouping not working

    Help wanted · · · – – – · · ·
    3
    9
    495
    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.
    • Pam Rathmell
      Pam Rathmell last edited by

      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
      (\d{4})(<)
      String to search in
      <td>2008</td>
      Replacement String
      <a href=“…/\1/\1.html”>\1</a>\2
      Result
      <td><a href=“…//.html”></a>/td>
      Desired Result
      <td><a href=“…/2008/2008.html”></a>/td>

      1 Reply Last reply Reply Quote 2
      • Pam Rathmell
        Pam Rathmell last edited by Pam Rathmell

        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.

        1 Reply Last reply Reply Quote 0
        • Ekopalypse
          Ekopalypse last edited by

          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 ?

          1 Reply Last reply Reply Quote 0
          • Pam Rathmell
            Pam Rathmell last edited by

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

            1 Reply Last reply Reply Quote 1
            • Pam Rathmell
              Pam Rathmell last edited by Pam Rathmell

              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

              Ekopalypse 1 Reply Last reply Reply Quote 1
              • Ekopalypse
                Ekopalypse @Pam Rathmell last edited by

                @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?

                1 Reply Last reply Reply Quote 0
                • Pam Rathmell
                  Pam Rathmell last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • Pam Rathmell
                    Pam Rathmell last edited by

                    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.

                    Alan Kilborn 1 Reply Last reply Reply Quote 1
                    • Alan Kilborn
                      Alan Kilborn @Pam Rathmell last edited by

                      @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. :(

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post
                      Copyright © 2014 NodeBB Forums | Contributors