我需要从外部文件加载一些必须执行的正则表达式。。。你知道吗
算法不需要知道它们是什么类型的正则表达式。。。但最后必须打印标签
email_re=["EMAIL","([^@|\s]+@[^@]+\.[^@|\s]+)"];
phone_re=["PHONE","(\d{3}[-\.\s]??\d{3}[-\.\s]??\d{4}|\(\d{3}\)\s*\d{3}[-\.\s]??\d{4}|\d{3}[-\.\s]??\d{4})"];
regexs=[email_re,
phone_re]
for regex in regexs:
#print regex
match = re.search(regex[1], prodotto)
if match:
print regex[0]+": "+match.group()
创建regexs数组定义外部文本文件中的所有regex的最佳方法是什么?你知道吗
使用json作为外部文件,请尝试以下操作:
json文件:
相关问题 更多 >
编程相关推荐