Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

regex

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?

like image 500
Oswaldo Nickel Avatar asked Mar 01 '23 21:03

Oswaldo Nickel


1 Answers

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.

like image 172
Wiktor Stribiżew Avatar answered Apr 09 '23 19:04

Wiktor Stribiżew