捕获组在 Sublime Text RegReplace 包中不起作用

Capture groups not working in Sublime Text RegReplace package

这是原文HTML:

<td class="danish">newtext</td>
<td><?php audioButton("../../audio/lessons/01/oldtext","oldtext"); ?></td>
<td><?php audioButton("../../audio/lessons/01/slow/oldtext_slx","oldtext_slx","1"); ?></td>

我想使用 Sublime Text 2 中的 RegReplace 包将 'oldtext' 替换为 'newtext'。

这是我的reg_replace.sublime-settings(不用分析全了,关键是里面有几个(.*)):

{
"replacements": {
    "audiobutton_rep": {
                "find": "<td class=\"danish\">(.*)</td>\n.*<td><\?php audioButton\(\"(.*)/.*\",\".*\"\); \?></td>\n.*<td><\?php audioButton\(\"(.*)/.*\",\".*\",\"1\"\);.*\?></td>",
                "replace": "<td class=\"danish\"></td>\n<td><?php audioButton(\"/\",\"\");?></td>\n<td><?php audioButton(\"/_slx\",\"_slx\",\"1\");?></td>",
                "greedy": true,
                "case": false
    },

这是default.sublime-commands中的命令:

{
    "caption": "Reg Replace: XXXXXXXXXXXXXXXX",
    "command": "reg_replace",
    "args": {"replacements": ["audiobutton_rep"] }
 },

捕获组不起作用,所以输出如下所示:

<td class="danish"></td>
<td><?php audioButton("/","");?></td>
<td><?php audioButton("/_slx","_slx","1");?></td>

当我 运行 它单独运行时,它工作得很好,但在这里不是。

您应该使用 \1\2\3 而不是 </code>、<code></code>。</p> <p>Sublime Text 的内置 search/replace 使用 Boost 库,它在替换字符串中接受 <code></code>,而大多数其他风格只接受 <code> .但是 RegReplace 是用 Python 写的,它只使用反斜杠。