vim - Regex search and replace in VI -


I have a lot of & lt; Swf ...> ..... and . I want to remove all of these. When using Vi I

 :% s / \ & lt; Swf [^ \ / swf & gt;] + \ / swf \ & gt; // g  

I was hoping that this would work, but it does not match anything.

You can delete all those buffers with this command:

 :% s! & Lt; Swf. \ {-} / swf & gt; !!  

If you have tags that can be divided into two rows, then you can add \ _ modifier to . also:

 :% s! & Lt; Swf \ _. \ {-} / swf & gt; !!  

Assuming that you want to delete both tags and whatever they are included, if you want to get rid of the tags and keep the content

 :!% S & lt;?. / \ Swf \ {-} & gt; !!  

Notes:

  • You will see & lt; or & gt; Do not need to be avoided
  • You can select which pattern delimiter: using the first letter you put after the s in the VIM option code This will remove the need to avoid further slash in your pattern

EDIT: My answer is growing after your comment

  • This All right / STRING / REPLACE / g I only ! Instead of / > I do not need to cite a backslash in the pattern (see my second thing above)
  • I used the g modifier Finally, from my : set to .vimrc (this means that by default all the matches are just one ) instead of the line
  • Turning the meaning of \ {-} to * is the "ungreedy" version, Code> Quantifier, i.e. 0 or more of the preceding molecule Matches feel some - This helps to ensure that your search pattern will extend past instead of before "closing" tag.

HTH


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -