Simplify tagre regex.
This commit is contained in:
parent
9c032c9006
commit
b3e51ddc93
1 changed files with 5 additions and 1 deletions
|
@ -42,6 +42,10 @@ def tagre(tag, attribute, value, quote='"', before="", after=""):
|
||||||
@return: the generated regular expression suitable for re.compile()
|
@return: the generated regular expression suitable for re.compile()
|
||||||
@rtype: string
|
@rtype: string
|
||||||
"""
|
"""
|
||||||
|
if before:
|
||||||
|
before += "[^>]*"
|
||||||
|
if after:
|
||||||
|
after += "[^>]*"
|
||||||
attrs = dict(
|
attrs = dict(
|
||||||
tag=case_insensitive_re(tag),
|
tag=case_insensitive_re(tag),
|
||||||
attribute=case_insensitive_re(attribute),
|
attribute=case_insensitive_re(attribute),
|
||||||
|
@ -50,7 +54,7 @@ def tagre(tag, attribute, value, quote='"', before="", after=""):
|
||||||
before=before,
|
before=before,
|
||||||
after=after,
|
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):
|
def case_insensitive_re(name):
|
||||||
|
|
Loading…
Reference in a new issue