如何替换每行中第二个匹配的单词?

问题描述 投票:0回答:1

我有一个包含大约10000行的txt文件。在每一行中,我有一个特定的字符(%20)重复了两次。我需要用另一个词来替换第二次出现的字符,并保留第一次出现的字符。有什么Notepad++正则表达式可以解决这个问题吗?

这是我的文本。

My name is %20John. my friend's name is %20john too.
My name is %20paul. my friend's name is %20paul too.
.
.

我需要它像这样

My name is %20John. my friend's name is john too.    
My name is %20paul. my friend's name is paul too.
regex replace notepad++
1个回答
2
投票

你可以用这样的方法。

^(.+?%20.+?)%20

...然后用..:

\1

...这样就可以删除第二个出现的... %20. 如果你想用其他的东西来代替它(如, SomeWord),你可以使用 \1SomeWord 在 "替换为 "字段中。

演示.

© www.soinside.com 2019 - 2024. All rights reserved.