如何判断字符串是否匹配正则表达式?
如果字符串与正则表达式匹配,我想找到 True。
正则表达式:
r".*apps\.facebook\.com.*"
我试过:
if string == r".*apps\.facebook\.com.*":
但这似乎行不通。
请您参考如下方法:
来自 Python 文档:on re module, regex
import re
if re.search(r'.*apps\.facebook\.com.*', stringName):
print('Yay, it matches!')
因为 re.search 如果找到则返回 MatchObject,如果找不到则返回 None。
