From b3e51ddc93f4fc922172149a597439067673795c Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Fri, 12 Oct 2012 21:47:41 +0200 Subject: [PATCH] Simplify tagre regex. --- dosagelib/util.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dosagelib/util.py b/dosagelib/util.py index bc463aea5..d89d378cd 100644 --- a/dosagelib/util.py +++ b/dosagelib/util.py @@ -42,6 +42,10 @@ def tagre(tag, attribute, value, quote='"', before="", after=""): @return: the generated regular expression suitable for re.compile() @rtype: string """ + if before: + before += "[^>]*" + if after: + after += "[^>]*" attrs = dict( tag=case_insensitive_re(tag), attribute=case_insensitive_re(attribute), @@ -50,7 +54,7 @@ def tagre(tag, attribute, value, quote='"', before="", after=""): before=before, after=after, ) - return r'<\s*%(tag)s\s+(?:[^>]*%(before)s[^>]*\s+)?%(attribute)s\s*=\s*%(quote)s%(value)s%(quote)s[^>]*%(after)s[^>]*>' % attrs + return r'<\s*%(tag)s\s+(?:[^>]*%(before)s\s+)?%(attribute)s\s*=\s*%(quote)s%(value)s%(quote)s[^>]*%(after)s>' % attrs def case_insensitive_re(name):