I'm trying to clean a Frontpage-generated html file, and there are a ton of tag attributes I need to delete, like:
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 delete a set number of wildcards with a simple . command:
:%s/ style="........"//g
But is there a way to make the . variable length in that substitute command, so that one command will delete every style attribute in the whole document?
PS - I've searched for frontpage cleaners and found a few, but not clear how reliable they are, so scripting it myself instead. Open to suggestions here though.
This should eliminate all the style attributes in your HTML:
:%s/ style=".*"//g
Edit: Sam Brinck brings up a good point. My code was based on your example alone. This code would gobble up too much, say if there were other attributes following the style="..."
attribute. A safer alternative may be:
:%s/ style="[^"]*"//g
which means - remove all characters after style="
that is NOT a double quote [^"]
until the next double quote is encountered. Thanks Sam!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With