To make sure that the entire string matches, you need to use the
end-of-string anchor:
def fullmatch(regex, string, flags=0):
"""Emulate python-3.4 re.fullmatch()."""
return re.match("(?:" + regex + r")", string, flags=flags)
The A
anchor is not necessary since re.match()
already anchors the match to the start of the string.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…