Regex for Finding classes in HTML files -
i have bunch of html files need search find class name used in application.
ex1: should match both of these:
<div class="something else field">foo</div> <span class="field">bar</span>
ex2: should not match
<div class="baseball-field baz">baz</div>
i need pattern find class name in files
what i've tried is: /class(?=field)/
but doesn't work, i'm not sure how account possible other characters in search.
update:
i tried: class.*(?=field)
, works ex1 not 2
your regex correct want search class="field"
while regex check classfield
.
so, can use regex instead:
class(?=="field")
in addition, not sure tool/language using, consider using html parser instead or xpath/xquery instead.
update: since updated question, here provided updates answer. use regex instead:
class(?=="(?:field|.*?\sfield|field\s.*?)")
btw, if want merge above alternations use:
class(?=="(?:(?:.*?\s)?field(?:\s.*?)?)")
you clean bit regex above removing non-capturing groups to
class(?=="((.*?\s)?field(\s.*?)?)")
Comments
Post a Comment