Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 998341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:10:42+00:00 2026-05-16T07:10:42+00:00

<created> pat@c.com </created> I want to replace the above with but the username may

  • 0
  <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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:10:43+00:00Added an answer on May 16, 2026 at 7:10 am

    It depends on the formatting that you want, but for the specific example that you quote, you could do one of these:

    Really simple, without context: replace pat@c.com with tom@c.com

    :%s/pat@c\.com/tom@c.com/g
    

    With context

    :%s:<created>\s*\n\s*\zs.\{-}\ze@c\.com\s*\n\s*</created>:tom
    

    By way of explanation:

    :%s:XXX:YYY - Substitute XXX with YYY over the whole file (using colons as delimiters to avoid having to escape slashes or @s with a backslash)
    
    where XXX is:
    <created> - literal text to search for
    \s*       - soak up any spaces or tabs to the end of the line
    \n        - a new line character
    \s*       - soak up any spaces or tabs at the start of the line
    \zs       - special code that says "the match starts here", so only the bit between this and the \ze are actually replaced
    .\{-}     - catch any characters, as few as possible - this will match 'pat' in the example above
    \ze       - end of the bit we're changing
    @c        - literal text - the @ and the start of the domain name
    \.        - '.' means any character, so to match a literal dot, you must escape it
    com       - literal text - the end of the email address
    \s*       - any spaces/tabs to the end of the line
    \n        - a new line character
    \s*       - any spaces/tabs
    </created> - literal match on the terminator (works because we don't use '/' as the delimiters)
    
    and YYY is just the literal string "tom" to insert
    

    An alternative formation:

    :%s:<created>\_s*\zs\S\+\ze\_s*</created>:tom@c.com
    
    :%s:XXX:YYY: - as before
    
    where XXX is:
    
    <created>  - literal text to search for
    \_s*       - search for zero or more white-space characters, including new-lines (hence the underscore)
    \zs        - as before, this is the start of the bit we want to replace (so we're not changing the <created> bit)
    \S\+       - one or more non-whitespace characters (\+ is one or more, * is zero or more) - this should catch the whole email address
    \ze        - as before, the end of the match
    \_s*       - zero or more white-space characters
    </created> - the end delimiter
    
    YYY is then the whole email address.
    

    I hope that gives you some helpful information. There are lots of useful reference guides on regular expressions (which is what these are) on the web (although note that Vim uses a slightly different format to most: \+ instead of + etc). I’d strongly recommend reading:

    :help pattern.txt
    

    But bear in mind there’s a lot in there, so read it gradually and experiment. You can also start by using a simple search (press /) and thinking about doing a substitution later, e.g. type:

    /<created>\_s*\zs\S\+\ze\_s*<\/created>
    

    Note that I’ve prefixed the / with a backslash as the search start is /. A clever trick with this is that :s by default uses the last search, so you can type the line above (/<created>\_s*\zs\S\+\ze\_s*<\/created>) and tweak it until it’s right, then just do :%s::tom@c.com and since the bit marked XXX above is absent, it’ll use your last search and just work!

    If there are any bits above you don’t understand, :help is your friend. For example, to find out about \zs, type:

    :help \zs
    

    For information about \_s, type:

    :help \_s
    

    For general information about :s type:

    :help :s
    

    etc…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is quite obscure, I may just be missing something extremely simple. Scenario 1
Not quite sure if it is ok to do this but, my question is:
I'm not exactly an expert at this, but I'm pretty sure I have covered
my setup is ubuntu - gitolite - msysgit. After following this tutorial : https://sites.google.com/site/senawario/home/gitolite-tutorial
I want to get the last user profile . But i am not able
I have this error, and i roughly know where it is, but do not
I have a table trigger like below: CREATE OR REPLACE TRIGGER PAT_BUR_DOB_TRG BEFORE UPDATE
I have a MySQL query like this: SELECT DAYNAME(CreatedAt) AS TheDay, SUM(Amount) AS TheSum
Created .NET WCF service, tested it - works. Generated schemas from Data and service
Created Private Key & Self signed certficate in a Key Store keytool -genkey -alias

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.