在 sublimetext2 中使用正则表达式替换 [英] Replace using regex in sublimetext2

查看:42
本文介绍了在 sublimetext2 中使用正则表达式替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用正则表达式(最好在 sublimetext2 中)来替换以下内容:

I would like to use regex (preferably in sublimetext2) to replace the following:

<td class="etword">et alfabet</td>
<td class="etword">&nbsp;</td>

这样:

<td class="etword">et alfabet</td>
<td class="etword"><?php audioButton("../../audio/words/et_alfabet","et_alfabet");?></td>

非常感谢!

推荐答案

Sublime Text

找什么:

<td class="etword">(.*?)</td>\n<td class="etword">&nbsp;</td>

替换为

<td class="etword">$1</td>\n<td class="etword"><?php audioButton("../../audio/words/$1","$1");?></td>

这将填充第二个表格单元格.但是,如果第一个单元格中有空格,则在 URL 中会有空格.不幸的是,只有正则表达式不能做到这一点,所以我们必须使用 Sublime Text 的一些其他功能来完成它.

This will fill the second table cell. However in the URL there will be spaces if there were spaces in the first cell. Unfortunately just regular expressions cannot do that, so we have to use some other features of Sublime Text to get it done.

Search (CTRL+F) for audioButton\(".*?\); 然后点击Find All".这样,所有的 audioButton-calls 将被选中.然后,不要点击任何其他东西,再次打开搜索/替换面板 (CTRL+H) 并将 (空格字符)替换为 _(下划线).确保在选择中"选项被激活.然后点击全部替换",一切都应该没问题.

Search (CTRL+F) for audioButton\(".*?\); and click "Find All". That way, all the audioButton-calls will be selected. Then, without clicking anything else, open up the search/replace panel again (CTRL+H) and replace (space character) with _ (underscore). Make sure that the "In selection"-option is activated. Then click "Replace All" and everything should be fine.

这篇关于在 sublimetext2 中使用正则表达式替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆