0

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

1
  • 3
    This is a simple task for regular expressions. Show what you have already tried and explain why it does not do what you want. Commented Apr 23, 2014 at 12:06

3 Answers 3

2

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"/>
    
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.