Google Apps脚本,来自Gmail的getBody(),正则表达式\ n [英] Google apps script, getBody() from Gmail, regex \n
问题描述
晚上好.
Google应用程序脚本中的正则表达式换行符("\ n")存在此类问题.我正在使用.getbody()方法进行邮件解析,并得到其中的一部分
Good evening.
Have such problem with regex new-line character ("\n") in Google app script. I'm using .getbody() method for mail parse and get some of this
<td valign="middle" width="43" align="left">
<img src="http://img/mail-new-oct/icon2.png" style="display: block; vertical-align: middle;" alt="Logo">
</td>
<td align="center" valign="top" style="font-family: 'Open Sans', Helvetica, 'Helvetica Neue', Arial, sans-serif; font-size: 13px; line-height: 30px; color: #000000; font-weight: 400; text-align: left;">0972398182
</td>
为此,我需要电话号码0972398182. 我尝试使用以下表达式获取它:
For this part, i need phone number 0972398182. I try get it with this expression:
icon2.*\n.*\n.*>\s*([\s\S]+?)\s*(?=<\/td>)
icon2-是此html正文的唯一标识,因此我需要使用它.
这样就不可能没有("\ n")进行操作,最后它是行不通的.我读到,GAS无法与("\ n")一起使用,但也许还有其他方法可以解决此问题?
感谢您的帮助!
icon2 - is one unique identification for this html body, so i need to use it.
Go through without ("\n") impossible in this way, and finally it doesn't work. I read, that GAS doesn't work with ("\n") , but maybe have other way how to solve this?
Will be grateful for any help, thanks!
推荐答案
您似乎在输入字符串中结合了换行符和回车符.这意味着您可以在+
量词中使用[\r\n]+
字符类:
You seem to have a combination of newlines and carriage returns in your input string. That means you may use [\r\n]+
character class with +
quantifier:
icon2.*[\r\n]+.*[\r\n]+.*left.*>\s*(.+?)\s*(?=<\/td>)
这篇关于Google Apps脚本,来自Gmail的getBody(),正则表达式\ n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!