[英]replace text using regular Expression in Notepad++
I have following text as input. 我有以下文字作为输入。
1 "India" 1 "IN"
2 "Germany" 2 "GM"
3 "Canada" 3 "CN"
4 "United States" 4 "US"
and I want to convert all this strings to following pattern 我想将所有这些字符串转换为以下模式
<value in="India" out="IN"/>
<value in="Germany" out="GM"/>
<value in="Canada" out="CN"/>
<value in="United States" out="US"/>
How to do it using regular expression? 如何使用正则表达式? I am using notepad++ 我正在使用记事本++
Make sure you place the cursor at the beginning of the file. 确保将光标放在文件的开头。
CTRL+H
. 点击CTRL+H
Replace
tab. 选择“ Replace
选项卡。 Select Regular Expression
at the bottom. 选择底部的Regular Expression
。
Find: \\d+\\s+"(.*?)".*?"(.*?)" Replace: <value in="\\1" out="\\2"/>
I don't have Notepad++, but in SubEthaEdit, I would do this: 我没有Notepad ++,但在SubEthaEdit中,我会这样做:
Find: 找:
[^"]*("[^"]*")[^"]*("[^"]*")[^"]*
(five sections of "not a quote", separated by quotes, capturing the two quoted parts) (“引用”的五个部分,用引号分隔,捕获两个引用的部分)
Replace: 更换:
<value in=\1 out=\2/>\n
This ought to be very similar in Notepad++. 这在Notepad ++中应该非常相似。
find : ^.*?"([^"]+)"[^"]+"(\\w+)"
find: ^.*?"([^"]+)"[^"]+"(\\w+)"
replace with : <value in="\\1" out="\\2"/>
替换为: <value in="\\1" out="\\2"/>
output : 输出:
<value in="India" out="IN"/>
<value in="Germany" out="GM"/>
<value in="Canada" out="CN"/>
<value in="United States" out="US"/>
demo here : http://regex101.com/r/hH3rZ4 这里演示: http : //regex101.com/r/hH3rZ4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.