Twil
Twil

Reputation: 107

Google apps script, getBody() from Gmail, regex \n

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>

For this part, i need phone number 0972398182. I try get it with this expression:

icon2.*\n.*\n.*>\s*([\s\S]+?)\s*(?=<\/td>)

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!

Upvotes: 2

Views: 950

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626689

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>)

Upvotes: 1

Teyam
Teyam

Reputation: 8082

Please try the given workaround in Issue #13 logged in google-apps-script-issues tracker. Use:

\\n.

In addition to that, you may want to also check solutions given in the following posts:

Upvotes: 0

Related Questions