#!/usr/local/bin/python2 # coding: utf-8 import re r = re.compile(u"""<("[^"]*"|'[^']*'|[^'">])*""" u"""class[\t\n\f\r\u0020]*=[\t\n\f\r\u0020]*[item|"item"|'item'|]""" u"""("[^"]*"|'[^']*'|[^'">])*>""") print r.match("""