Search and replace regular expressions in VI

I have a document with a lot of <swf ...> ..... </swf> in it. I would like to remove all this. Using vi as you type

:%s/\<swf[^\/swf>]+\/swf\>//g

I was hoping this would work, but nothing matches.

+3
source share
2 answers

You can delete everything from the buffer with this command:

:%s!<swf.\{-}/swf>!!

if you also have tags that can be split into two lines, you can add a modifier \_to .match newline characters:

:%s!<swf\_.\{-}/swf>!!

assuming you want to remove both the tags and what they contain if you just want to get rid of the tags and save the content

:%s!</\?swf.\{-}>!!

Notes:

  • you do not need to run <or>
  • , : Vim , s substitute:

EDIT:

  • , /STRING/REPLACE/g ! /, (. ).
  • g , :set gdefault my .vimrc, ( , Vim , , /g)
  • \{-} - "" *, 0 , - , " " .

+8

, [] , , swf s, w f , .

- :

\<swf.\{-}\/swf\>

, . .

Vim, , . , .

+3

Source: https://habr.com/ru/post/1731061/


All Articles