Community
    • Login

    Search and Replace With Backwards Direction Checked Doesn't capture groups

    Scheduled Pinned Locked Moved General Discussion
    2 Posts 2 Posters 580 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.
    • Eightvo 8080E
      Eightvo 8080
      last edited by

      I was having trouble with search and replace and found a site that claimed Using Search and Replace With Patterns:
      Capture ([\d]+):
      Replace: prefix_\1_suffix
      Against Text:

      12343:
      123a:
      1111:
      222
      333:

      Produces:
      prefix_12343_suffix
      123a:
      prefix_1111_suffix
      222
      prefix_333_suffix

      Which is true… unless you have “Backwards direction” checked, the cursor at the end of the file and press “Replace”.
      (Replace all seems to work)… but just replace results in:
      prefix__suffix
      123a:
      prefix__suffix
      222
      prefix__suffix

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Eightvo 8080
        last edited by Alan Kilborn

        @Eightvo-8080

        So you haven’t mentioned the magic words, but clearly you are working with “regular expressions” or “regex”.

        Searching in a backward direction with regex has known problems and is partially disabled in Notepad++ currently (7.8.4) – but this isn’t a new problem, it has probably existed back to the days when regex capability was first introduced in version 6.0.

        If would be nice if it were either (a) fully disabled OR (b, as in “better”) made to work right.

        Unless and until it is made to work correctly, backward regex capture groups not working as intended is not surprising. I don’t think there’s any kind of workaround; sorry.

        1 Reply Last reply Reply Quote 3
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors