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
. Replace
tab. Select Regular Expression
at the bottom.
Find: \\d+\\s+"(.*?)".*?"(.*?)" Replace: <value in="\\1" out="\\2"/>
I don't have Notepad++, but in SubEthaEdit, I would do this:
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++.
find : ^.*?"([^"]+)"[^"]+"(\\w+)"
replace with : <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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.