Loading ...
Sorry, an error occurred while loading the content.

113514Re: Search & Replace

Expand Messages
  • Christian Brabandt
    Apr 2, 2010
    • 0 Attachment
      Hi Kunal!

      On Fr, 02 Apr 2010, Kunal Bajpai wrote:

      > To this html code I wanted to select the text between the tags and replace
      > the original text with \n character removed. There is a more complex example
      > that I wanted to ask, here is the problem:
      > Original
      > ______________________________
      > <p>Mike
      > <strong>Gilbert </strong>
      > Senior</p>
      > _____________________________
      > After search & replace:
      > ______________________________
      > <p>Mike <strong>Gilbert</strong> Senior</p>
      > _____________________________
      > I hope you really got what I was asking.

      Try this:
      :%s/\(<p>\)\(\w\+\)\_s*\(\w\+\)\_s*\(\w\+\)\(<\/p>\)/\1 \2 <strong>\3<\/strong> \4 \5/
      (one line)

      which boils down to:
      :%s/ " substitute on every line
      " anything that matches
      \(<p>\) " the <p> tag and remember it
      \(\w\+\) " a word (which means a string that
      " matches the range 0-9A-Za-z_ but no space
      " and remember it
      \_s* " a space or linebreak
      \(\w\+\) " a word and remember it (see above)
      \_s* " a space or line break
      \(\w\+\) " a word and remember it (see above)
      \(<\/p>\) " the closing tag (and remeber it)
      / " and replace the match part
      \1 " the first remembered string followed by a space
      \2 " the second remembered string followed by a space
      <strong> " the strong tag
      \3 " the third remembered string followed by
      <\/strong> " the closing tag followed by a space followed by
      \4 " the 4th remembered word followed by a space and
      \5 " the 5th remembered word


      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      To unsubscribe, reply using "remove me" as the subject.
    • Show all 10 messages in this topic