How can I match the contents of all divs that have a specific class. For example:
<div class="column-box-description paddingT05">content</div>
Generally, you shouldn't do this with regex unless you can make strong assumptions about the text you're matching; you'll do better with something that actually parses HTML.
But, if you can make these stronger assumptions, you can use:
<div class="[^"]*?paddingT05[^"]*?">(.*?)<\/div>
The key part is the reluctant quantifier *?
which matches the minimal text possible (i.e. it doesn't greedily eat up the </div>
.
You can do something like this:
<div.*class\s*=\s*["'].*the_class_you_require_here.*["']\s*>(.*)<\/div>
Replace "the_class_you_require_here" with a class name of your choosing. The div content is in the first group resulted from this expesion. You can read on groups here: http://www.regular-expressions.info/brackets.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With