Regular expression for finding class names in HTML

前端 未结 4 716
我在风中等你
我在风中等你 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:14

    Don't do it. It will drive you insane: RegEx match open tags except XHTML self-contained tags

    Instead, use a HTML parser. It's not hard.

    EDIT: Here's an example in PowerShell

    Get-ChildItem -Recurse *.html | where { 
        ([xml](Get-Content $_)).SelectNodes( '//*' ) | where { $_.GetAttribute( "class" ).Contains( "foo" ) } 
    }
    

提交回复
热议问题