Match An Html Attribute
Join the DZone community and get the full member experience.Join For Free
The goal of this expression is to match all "id" attributes of the "div" tags on a page
) . )* # Consume everything until finding " id=" or ">" # (">" is just for failing faster) \sdiv=(?P<__quote>['"])? # Consume " div=" and save the quote type (' or ") if any (?: # while (?! # next character isn't, (?(__quote) # if a quote has been opened, (?P=__quote) # the closing quote ; |[\s>] # a space or ">" else, ) ) . # consume this character )* (?(__quote) # If we got a quote (?P=__quote)| # it must be closed (?=[\s>]) # else, the attribute is ended by a space or ">" ) [^>]*> # Consume the rest of the tagTopics:
Opinions expressed by DZone contributors are their own.