Finding and replacing a Vim variable-length pattern?

I am trying to clear the html file created in Frontpage and there are a ton of tag attributes that I need to delete, for example:

style="font-size: 10.0pt; font-family: Trebuchet MS; color: blue" style="color: blue; text-decoration: underline; text-underline: single" style="color: blue; text-decoration: underline; text-underline: single" style="font-family: Trebuchet MS" style="font-size:10.0pt;" style="color: navy" 

I can remove a given number of wildcards with a simple one. Command:

 :%s/ style="........"//g 

But is there a way to do it. variable length in this wildcard so that one command removes every style attribute in the entire document?

PS - I looked for cleaners on the first page and found several, but I did not understand how reliable they are, so instead of scripting itself. However, offers open to suggestions.

+4
source share
1 answer

This should eliminate all the style attributes in your HTML:

 :%s/ style=".*"//g 

Edit : Sam Brink is raising a good point. My code was based only on your example. This code would gobble up too much, say, if there were style="..." attributes. A safer alternative might be:

 :%s/ style="[^"]*"//g 

which means to delete all characters after style=" , which is not a double quote [^"] , until the next double quote is encountered. Thanks to Sam!

+11
source

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


All Articles