1
 <created>
  pat@c.com 
</created>

I want to replace the above with but the username may vary i.e,pat@c.com ,harry@c.com...

  <created>
   tom@c.com
  </created>

What is the command to replace this in vim

 %s/<created>\r*\r</created>/new string
Andrew
  • 8,002
  • 3
  • 36
  • 44
Hulk
  • 391
  • 1
  • 6
  • 17

1 Answers1

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
chmeee
  • 7,370
  • 3
  • 30
  • 43