我有一个电子邮件模板,它有html格式的电子邮件上下文,
现在我想从电子邮件html内容中找到邮政编码
为此,我使用regex来搜索邮政编码,内容如下格式1:
helllo this is the mail which will converted in the lead
and here is some addresss which will not be used..
and the
zip: 364001
city: New york
甲酸盐2:
<p><b>Name</b></p><br/>
fname
<p><b>Last Name</b></p><br/>
lname
<p><b>PLZ</b></p><br/>
71392
<p><b>mail</b></p><br/>
heliconia72@mail.com
代码看起来像
regex = r'(?P<zip>Zip:s*dddddd)'
zip_match = re.search(regex, mail_content) # find zip
zip_match.groups()[0]
这只是在搜索formate 2,我如何才能写一个正则表达式,使其同时适用于甲酸盐。
如果你真的需要使用regex(我可能会使用BeautifulSoup
作为第二个),你可以使用这个例子:
regex = r'(?:zip:s*|PLZ</b></p><br/>n)(d{5})'
zip_match = re.search(regex1, mail_content)
zip_match.groups()[0]