我使用Google Apps脚本解析邮箱。 我在识别要解析的消息时没有遇到任何问题,当我想从消息的plainBody中获取特定的文本块时,问题就出现了。
平原身份的摘录:
Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the server for the recipient domain domain.com by aspmx.l.google.com. [173.194.77.26].
The error that the other server returned was:
550-5.1.1 The email account that you tried to reach does not exist. Please try
550-5.1.1 double-checking the recipient's email address for typos or
550-5.1.1 unnecessary spaces. Learn more at
550 5.1.1 http://support.google.com/mail/bin/answer.py?answer=6596 y3si2744337oex.60 - gsmtp
----- Original message -----
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20130820;
我试图抓住所有以550开头的行(至少,在本例中他们以550开头,可能是任意数量的代码开始这些行)
我试图抓住它的代码是
var bodyRegex = new RegExp("The error that the other server returned was:[\s\S]*----- Original message -----");
Logger.log(bodyRegEx.exec(plainBody));
它只是返回 null
使用RegExLib我能够成功使用此RegEx
答案 0 :(得分:0)
尝试转义斜杠,因为您正在编译RegExp对象:
var bodyRegex = new RegExp("The error that the other server returned was:[\\s\\S]*----- Original message -----");
或只使用文字:
var bodyRegex = /The error that the other server returned was:[\s\S]*----- Original message -----/;