使用两个选项查找和替换某个字词

时间:2017-06-14 15:53:12

标签: html regex notepad++

所以我想用notepad ++来提高我工作的效率,我希望用Notepad ++或任何其他方法来实现我想要的东西。

是否有可能找到替换让我们说" USA"与"英国"和#34;联合王国"反之亦然。

我正在使用网址,并且需要通过手动更换“联合王国”进行冲洗和重复操作。与美国或"英国"到了#34;联合王国"

如果这根本不可能,那么谢谢你的时间。

无法显示代码,因为它是保密的。感谢。

我能做的最好的事情是:

案例1:

Lorem Ipsum is simply dummy text of the printing and typesetting industry
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type specimen book
<a href="http://www.sample.com/book/lorem-ipsum/">Lorem Ipsum</a>

为:

The Dominican Republic is simply dummy text of the printing and typesetting industry
The Dominican Republic has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type specimen book
<a href="http://www.sample.com/book/the-dominican-republic/">The Dominican Republic</a>

案例2:

USA is simply dummy text of the printing and typesetting industry
USA has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type specimen book
<a href="http://www.sample.com/book/lorem-ipsum/">Lorem Ipsum</a>

为:

The Dominican Republic is simply dummy text of the printing and typesetting industry
The Dominican Republic has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type specimen book
<a href="http://www.sample.com/book/the-dominican-republic/">The Dominican Republic</a>

编辑:如果您阅读了我与回答过的人的对话,可以通过录制宏来解答,但我想我要么找一个非常具体的尚未制作的宏,要么我只需要手动搜索和替换&#34;

编辑2:添加了2个经常遇到的案例并进一步澄清。使用HTML,其中包含带有链接的文本段落,其中包含我需要替换的单词。显示了两个实例,因为有时候我需要用两个或多个具有两种不同格式的单词替换单个单词:URL形式应该取代USA到“United Kingdom”&#39;和美国到#34;英国&#34;。 Regex真的很新,我读的越多,我认为我想要的是通过一个表达式。

虽然我不知道是否可以通过代码来检测要替换的单词是否多于一个。像美国一样,表达式知道它只有一个单词,但如果要替换的单词是英国,则表达式知道需要替换两个单词。

TL; DR:REGEX是否可以在网址中搜索并替换单词和相同的单词,并用正确格式化的不同字符串替换它们?

也许指点我参考?

我理解我的问题很复杂,如果mod / s或其他任何人需要关闭它,我完全理解。

2 个答案:

答案 0 :(得分:0)

这就是宏的用途。

macro toolbar

使用红色按钮开始录制,替换一次,停止宏,然后使用第4个按钮直到EoF运行。

e:记得在录制后保存它,这样就可以保存你需要的两个。

e2:有关进一步说明,您要记录的内容有两个替换,一个用于United Kingdom,另一个用于united-kingdom然后停止宏。

答案 1 :(得分:0)

好的,我在这里得到了你想要的东西https://regex101.com/r/wbrd5Z/2

首先,您必须在文件的末尾复制要替换的字符串,我的情况是/united-kingdom/ /USA/

然后使用条件正则表达式来查找/ USA /或/ United Kingdom /

如果发现/USA/ /united-kingdom/,如果/United Kingdom/找到/USA/,则替换为my $substitute = "(1+l_tax)";

对于替换你使用\ 1来获取第一组的内容,搜索&#34; regex group&#34;。

使用notepad ++,您将打开查找并替换并标记正则表达式复选框。那么语法可能会有所不同。

如果您有任何疑问,请告诉我。