草庐IT

fullmatch

全部标签

python - 向后移植 Python 3. 4's regular expression "fullmatch()"到 Python 2

Python3.4引入了新的正则表达式方法re.fullmatch(pattern,string,flags=0).有没有人将这种新方法反向移植到旧的Python版本? 最佳答案 要确保整个字符串匹配,您需要使用\Zend-of-stringanchor:deffullmatch(regex,string,flags=0):"""Emulatepython-3.4re.fullmatch()."""returnre.match("(?:"+regex+r")\Z",string,flags=flags)\Aanchor不是必需的,因