This is a slight improvement in the response of Vasily Sirakis. It handles "…" and '…' completely separately and does not use the qualifier *? .
Regular expression
<[^'">]*(("[^"]*"|'[^']*')[^'">]*)*>
Demo
http://regex101.com/r/jO1oQ1
Explanation
< # start of HTML tag [^'">]* # any non-single, non-double quote or greater than ( # outer group ( # inner group "[^"]*" # "..." | # or '[^']*' # '...' ) # [^'">]* # any non-single, non-double quote or greater than )* # zero or more of outer group > # end of HTML tag
This version is slightly better than Vasilis, in that single quotes are allowed inside "…" , and double quotes are allowed inside '…' and that a (incorrect) tag, for example <a href='> , will not be matched.
This is slightly worse than Basil’s decision that the groups were captured. If you don't want this, replace ( with (?: In all places. (Just use ( makes the regex shorter and a little more readable).
zrajm
source share