• Login
Community
  • Login

Regex partial replacement syntax? Grouping not working

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
9 Posts 3 Posters 861 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.
  • P
    Pam Rathmell
    last edited by Aug 17, 2019, 1:17 PM

    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
    • P
      Pam Rathmell
      last edited by Pam Rathmell Aug 17, 2019, 1:58 PM Aug 17, 2019, 1:57 PM

      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
      • E
        Ekopalypse
        last edited by Aug 17, 2019, 2:13 PM

        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
        • P
          Pam Rathmell
          last edited by Aug 17, 2019, 2:24 PM

          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
          • P
            Pam Rathmell
            last edited by Pam Rathmell Aug 17, 2019, 3:19 PM Aug 17, 2019, 3:17 PM

            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

            E 1 Reply Last reply Aug 17, 2019, 4:02 PM Reply Quote 1
            • E
              Ekopalypse @Pam Rathmell
              last edited by Aug 17, 2019, 4:02 PM

              @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
              • P
                Pam Rathmell
                last edited by Aug 17, 2019, 4:04 PM

                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
                • P
                  Pam Rathmell
                  last edited by Aug 17, 2019, 4:24 PM

                  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.

                  A 1 Reply Last reply Aug 25, 2019, 9:51 PM Reply Quote 1
                  • A
                    Alan Kilborn @Pam Rathmell
                    last edited by Aug 25, 2019, 9:51 PM

                    @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
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors