如何在记事本++替换中分隔正则表达式组号?

How to delimit a regex group number in notepad++ replacement?

我想指定一个捕获的组,然后在替换项中指定一个字面数字,但字面数字被解释为组号的一部分。

给出这个(人为的)例子:

Input text: A5
Find: (.)(.)
Replace: 
Expected result: A6
Actual result: <blank>

实验表明 </code> 被解释为 "group 16"。</p> <p>我尝试使用 <code> 来制作 6 文字,这给了我第 1 组,但 ​​</code> 是空白 - 即结果只是 <code>A . \6 给了我 A.

一般的问题是,"how do I specify group 1 then a literal number"?

记事本 S&R 正则表达式由 Boost 正则表达式库提供支持。

明确的 $n 反向引用是通过 ID 周围的大括号 ({}) 实现的,因此,您可以在此处使用 6 作为替代。

Notepad++ 还支持以 \ 开头的 BRE 样式反向引用(</code>、<code> 等 * 到 9)。因此,当您在替换模式中使用 </code> 时,引擎只会将其解析为反向引用 1 + 文字符号 <code>6。您可以通过将 1234567890A 中的 (.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.) 替换为 </code> 来检查它。结果是 <code>A(第 11 组),而不是 11</code> 替换将导致 <code>A.

Notepad++ help 提到了这些符号,但缺少细节:

$n, ${n}, \n
Returns what matched the subexpression numbered n. Negative indices are not alowed.