如何调整rec.com以接受多种变体/选项?
目前正在处理此代码,该代码将扫描我的电子邮件并返回以下模式。例如,它将返回ABC123456行10 SEQ 1 1/1/2022。无论如何,我可以将线路和SEQ零件可选吗?例如,我的扫描仍然会拾取 ABC123456 1/1/2022 或 ABC123456行10 1/1/2022 ?
pattern = re.compile(r"([a-zA-Z]+[0-9]+) Line ([0-9]+) Seq ([0-9]) ([0-9]+/[0-9]+/[0-9]+)")
matches = pattern.finditer(body)
writer.writerows(map(lambda m: m.groups(), matches))
break
Currently working on this code that will scan my email and return all occurrences with the pattern below. For example, it would return ABC123456 Line 10 Seq 1 1/1/2022. Is there anyway I could make the Line and Seq parts optional? For example, my scan would still pick-up ABC123456 1/1/2022 or ABC123456 Line 10 1/1/2022?
pattern = re.compile(r"([a-zA-Z]+[0-9]+) Line ([0-9]+) Seq ([0-9]) ([0-9]+/[0-9]+/[0-9]+)")
matches = pattern.finditer(body)
writer.writerows(map(lambda m: m.groups(), matches))
break
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用REGEX
a | b
令牌,该令牌与表达式a
或b
匹配。因此,您的正则是:You may use the regex
a|b
token which matches either the expressionsa
orb
. So your regex could be: