Regular expression for finding class names in HTML

前端 未结 4 687
我在风中等你
我在风中等你 2021-01-14 09:40

I\'d like to use grep to find out if/where an html class is used across a bunch of files. The regex pattern should find not only

<

4条回答
  •  醉梦人生
    2021-01-14 10:17

    How about something like this:

    grep -Erno 'class[ \t]*=[ \t]*"[^"]+"' *
    

    That will also allow for more whitespace and should give you output similar to:

    1:class="foo bar baz"
    3:class = "haha"
    

    To see all classes used, you can pipe output from the above into the following:

    cut -f2 -d'"' | xargs | sort | uniq
    

提交回复
热议问题