gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 02:44:59 24 4
gpt4 key购买 nike

我想使用grep找出是否/何处在一堆文件中使用了 html 类。正则表达式模式不仅应该找到 <p class="foo">还有<p class="foo bar foo-bar">

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

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

有什么建议吗?谢谢!迈克

最佳答案

像这样怎么样:

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

这也将允许更多的空白,并且应该为您提供类似于以下内容的输出:

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

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

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

关于regex - 用于在 HTML 中查找类名的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1989579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com