1
 <created>
  [email protected] 
</created>

I want to replace the above with but the username may vary i.e,[email protected] ,[email protected]...

  <created>
   [email protected]
  </created>

What is the command to replace this in vim

 %s/<created>\r*\r</created>/new string

1 Answer 1

1

It worked for me like this:

%s/<created>\n\s*\w*@\w*\n<\/created>/newstring/

If you wanted to re-insert the e-mail address you can use:

%s/<created>\n\s*\(\w*@\w*\)\n<\/created>/newstring: \1/

A bit of explanation:

  • \n: newline
  • \s: spaces and tabs
  • \w: any word character
  • \( and \): capture what's inside
  • \1: use the first captured expression
5
  • 1
    Try using a different delimiter for clarity, since you have "/" in your pattern: "%s#<created>\n\s*\w*@\w*\n</created>#newstring#".
    – BMDan
    Commented Aug 6, 2010 at 13:59
  • Thanks guys,This is the first time i got a reply for a vim editor question.
    – Hulk
    Commented Aug 6, 2010 at 14:12
  • Can u explain the above.Not working for me now..
    – Hulk
    Commented Aug 6, 2010 at 14:25
  • @Hulk, updated my answer, how is not working?
    – chmeee
    Commented Aug 10, 2010 at 6:49
  • It is now.......
    – Hulk
    Commented Aug 26, 2010 at 5:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .