用于在HTML中查找类名的正则表达式

Mik*_*ike 3 regex grep

我想grep用来找出在一堆文件中是否使用html类.正则表达式模式不仅应该找到<p class="foo">而且还应该找到<p class="foo bar foo-bar">.

到目前为止,我能够通过下面的示例找到class ="foo",无法使其与多个类名一起使用:

grep -Ern "class=\"result+(\"| )" *

有什么建议?谢谢!麦克风

Kal*_*son 15

这样的事情怎么样:

grep -Erno 'class[ \t]*=[ \t]*"[^"]+"' *
Run Code Online (Sandbox Code Playgroud)

这也将允许更多的空格,并应该给你类似于以下的输出:

1:class="foo bar baz"
3:class = "haha"
Run Code Online (Sandbox Code Playgroud)

要查看所有使用的类,可以将上面的输出管道输出到以下内容中:

cut -f2 -d'"' | xargs | sort | uniq
Run Code Online (Sandbox Code Playgroud)