Notepad++ Regex replace - \1 doesn't work?

前端 未结 1 1914
清歌不尽
清歌不尽 2020-12-30 04:16

Just to preface, I have read many of the questions regarding this, but I couldn\'t find an answer (at least in my digging). Feel free to point it out if I did miss it!

相关标签:
1条回答
  • 2020-12-30 04:39

    \1 references the contents of the first capturing group, which means the first set of parentheses in your search regex. There isn't one in your regex, so \1 has nothing to refer to.

    Use \0 if you want to reference the entire match, or add parentheses around the relevant part of the regex.

    find: name[A-Z_0-9]+
    replace: \0_SUFFIX
    

    will change nameABC into nameABC_SUFFIX.

    Using capturing groups, you can do things like

    find: name([A-Z_0-9]+)     
    replace: \1_SUFFIX
    

    which will replace nameABC with ABC_SUFFIX.

    0 讨论(0)
提交回复
热议问题