gpt4 book ai didi

javascript - 如何改进正则表达式,使其可以匹配 google script 电子邮件抓取工具的电子邮件格式?

转载 作者:行者123 更新时间:2023-12-05 08:19:48 28 4
gpt4 key购买 nike

我正在尝试制作一个电子邮件抓取工具,它可以读取您的电子邮件并将交易记录放入 google 表格中以便于预算。

邮件格式如下:

This is an Alert to help you manage your credit card account ending in 0000.

As you requested, we are notifying you of any charges over the amount of ($USD) 0.01, as specified in your Alert settings. A charge of ($USD) 44.44 at UBER * EATS PENDIN has been authorized on Apr 34, 2073 at 2:27 PM ET.

Do not reply to this Alert.

If you have questions, please call the number on the back of your credit card, or send a secure message from your Inbox on www.bank.com.

To see all of the Alerts available to you, or to manage your Alert settings, please log on to www.bank.com.

我试图只获取价格 (44.44)、公司 (Uber Eats)、日期(2073 年 4 月 34 日)和时间(美国东部时间下午 2:27)。

我有这个作为我的正则表达式:

/A charge of\s\W+\w+\W+\s(.+?(?=at))\w+\s(.+?(?=has))\w+\s\w+\s\w+\s\w+\s(.+?(?=at))\w+\s(.+?(?=ET))/g

尽管它在 regex101 中匹配,但它不再工作。

关于如何让它在谷歌脚本中匹配以便抓取电子邮件的任何想法?其他一切正常

最佳答案

根据您展示的示例,您能否尝试以下操作。在此处使用 PCRE 功能,这将创建 3 个捕获组,您可以根据需要从中获取值。

^(?:As you requested.*\$USD\)\s+)(\d+\.\d+)\s+[\w]+\s+([^ ]*).*?authorized on(.*)\.$

Online demo for above regex

说明: 为以上添加详细说明。

^(?:                           ##Matching from starting of value, starting a non-capturing group.
As you requested.*\$USD\)\s+ ##Matching string As you requested. till $USD) spaces here.
) ##Closing non-capturing group here.
(\d+\.\d+) ##1st capturing group has digits DOT digits here.
\s+[\w]+\s+ ##Matching spaces word characters spaces here.
([^ ]*) ##2nd capturing group matches till any spaces(basically Uber value will come here).
.*?authorized on ##Matching everything till authorized on here.
(.*)\.$ ##Matching everything till last dot comes of the line, time and date basically.

关于javascript - 如何改进正则表达式,使其可以匹配 google script 电子邮件抓取工具的电子邮件格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67041555/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com