Question

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++

Was it helpful?

Solution 2

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

OTHER TIPS

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++.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top