这是原始的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\">$1</td>\n<td><?php audioButton(\"$2/$1\",\"$1\");?></td>\n<td><?php audioButton(\"$3/$1_slx\",\"$1_slx\",\"1\");?></td>",
"greedy": true,
"case": false
},
这是default.sublime-commands
中的命令:
{
"caption": "Reg Replace: XXXXXXXXXXXXXXXX",
"command": "reg_replace",
"args": {"replacements": ["audiobutton_rep"] }
},
捕获组不起作用,因此输出如下所示:
<td class="danish">$1</td>
<td><?php audioButton("$2/$1","$1");?></td>
<td><?php audioButton("$3/$1_slx","$1_slx","1");?></td>
当我自己运行它时它完美运行,但不是在这里。
答案 0 :(得分:2)
您应该使用\\1
,\\2
和\\3
代替$1
,$2
和$3
。
Sublime Text的内置搜索/替换使用Boost库,该库在替换字符串中接受$1
或\1
,而大多数其他版本仅接受$1
。但是RegReplace是用Python编写的,它只使用反斜杠。