如何调整rec.com以接受多种变体/选项?

发布于 2025-02-04 03:55:43 字数 393 浏览 2 评论 0原文

目前正在处理此代码,该代码将扫描我的电子邮件并返回以下模式。例如,它将返回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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事与诗 2025-02-11 03:55:43

您可以使用REGEX a | b令牌,该令牌与表达式ab匹配。因此,您的正则是:

r"([a-zA-Z]+[0-9]+)( Line ([0-9]+ )| )(Seq ([0-9]) |)([0-9]+\/[0-9]+\/[0-9]+)"

You may use the regex a|b token which matches either the expressions a or b. So your regex could be:

r"([a-zA-Z]+[0-9]+)( Line ([0-9]+ )| )(Seq ([0-9]) |)([0-9]+\/[0-9]+\/[0-9]+)"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文