简体   繁体   中英

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.

  1. Hit CTRL+H .
  2. Choose the Replace tab.
  3. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM