I'm looking for a regular expression to find all instances of a CSS class name in HTML markup. So far I have this, assuming row
is the class name that I'm looking for:
class=\"[a-zA-Z0-9\-_\s]*row[a-zA-Z0-9\-_\s]*\"
It correctly matches all of the following:
class="foo_bar bar row test"
class="row"
class="hello foo bar row"
class=" foo bar row test "
And correctly doesn't match this:
class="hello" row
Unfortunately it incorrectly matches these (false positives):
class="narrow"
class="rowdy"
What regex will find a specific CSS class name in HTML?
Update There are lots of comments about how I shouldn't parse the DOM with regex. My use case is to do a 'find all' in a large project with thousands of HTML files to find where specific CSS classes are being used. I'm not operating inside of a browser or have access to a DOM.