Reputation: 31
I have string in which i want to get content of only those DIV tags which does not have the class image
.
I am using this regular expression:
#<\s*?div\b[^>]*class="[^image]">(.*?)</div\b[^>]*>#s
but it escapes all the DIV tags, not just the ones with the class image
Upvotes: 0
Views: 420
Reputation: 5268
You're likely better off with a DOM parser instead.
In any case, here's a regex that should do what you're after:
<div[^>]+class="(?!(?:.+ )?image(?: .+)?")([^"]+)"
Demo: http://rubular.com/r/eekxdFdmFR
Upvotes: 1
Reputation: 473
The expression [^image]
will find only those classes that do not contain i
AND m
etc. letters. Maybe negative lookahead can do the trick:
#<\s*?div\b[^>]class=\"(?:(?!image).)*\">(.?)*>#s
It will dismiss the class="images"
etc. too, but I hope this is a good beginning. :)
PS: I don't know the last ]
is necessary or not, but it is missing from my regexp.
Upvotes: 0