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



  • 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



  • @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.


Log in to reply