如上图所示,想取出公司名称和联系地址,试了很多次都取不出来,应该是正则匹配有误,跪求大佬TAT指导
mc = re.compile(u"公司名称:.*?([\u4E00-\u9FA5])",re.DOTALL)
if mc.search(content):
company = str(mc.search(content))
else:
print(path + '\t' + 'not exist' + '\t' + 'company')
如上图所示,想取出公司名称和联系地址,试了很多次都取不出来,应该是正则匹配有误,跪求大佬TAT指导
mc = re.compile(u"公司名称:.*?([\u4E00-\u9FA5])",re.DOTALL)
if mc.search(content):
company = str(mc.search(content))
else:
print(path + '\t' + 'not exist' + '\t' + 'company')
import re
content = "公司名称:宇宙牛皮无限责任公司"
mc = re.compile(u"公司名称(:|:)(.*)",re.DOTALL)
if mc.search(content):
company = mc.search(content).group(2)
print(f"找到了公司:{company}")
else:
print(f"文本里没找打公司:{content}")
// Output:
找到了公司:宇宙牛皮无限责任公司