Oswaldo Nickel
Oswaldo Nickel

Reputation: 53

how to search and delete a series of attributs in html using vim?

i need help with vim and regex.

i have a html file with a lot of class="..." e.g.

            <td class="td_3"><p class="block_3">80 €</p></td>
        <td class="td_3"><p class="block_3">90 €</p></td>

Since i'm not using any css, i want to delete them. i tried:

:%s/class="[a-z0-9]"//g

but it's not working. What am i doing wrong?

Upvotes: 4

Views: 55

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626804

With class="[a-z0-9]" pattern, you match a single alphanumeric char in between quotes, while there may be any text other than double quotation mark.

You probably also want to remove the whitespaces before the class.

You may use

:%s/\s\+class="[^"]*"//g 

Here, \s\+ will match one or more whitespace chars, class=" matches a literal string, then [^"]* finds any zero or more chars other than " as many as possible and then a " matches the closing double quotation mark.

Upvotes: 7

Related Questions