【发布时间】:2017-01-11 03:15:06
【问题描述】:
这是原始的 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>
当我自己运行它时它可以完美运行,但不是在这里。
【问题讨论】:
-
在这种情况下可能不是很有帮助,但请记住:stackoverflow.com/a/1732454/2224996
-
好吧 :) 但它在大多数情况下都有效。也许我的运气终于用完了。
标签: regex sublimetext2