简体   繁体   中英

error when matching url from gmail body using google app script

I am newbie to Google Apps Script can some one please help me to match url from gmail body using google's app script below is the script i have tried but I am getting error when matching it from email body. I am able to get full message in variable mailmsg but I am failed to match it I have also pasted my mail body below I want to extract first https link from mail body

here is match statement

     var mailmsg = message[t][x].getPlainBody();
     var regexpmatch = mailmsg.match(/^(https?|chrome):\/\/[^\s$.?#].[^\s]*$/)[1];
     Logger.log(regexpmatch);

below is my email body from gmail

Download Data

 <https://testurl.ct.testdata.net/ls/click?upn=9VwHM0E24WA-2F- 
  2FuwWpvo09QzByap8Q1XZ3lwZOYwqoN3DdeK6YUcVokkOb2-2Boq9zJ4ZMqKkeFvE-2FkR1Rugi1jarDEORU- 
  2BZtK6x7Wjz0bDlMzaGaJTMEqlbz4WU8125U4HpFoz_bacS4DOsuE1jq 

Thanks,

Your Team

 <https://testurl.ct.testdata.net/ls/click?upn=UHpyaFHJ1bhBoqAjtHiHtIMeBu-2FwtyBJ- 
 2Fi9JleFeKj10XIQWU1NH69-2FFIhuNafdc2XG7_bacS4DOsuE1jq

In order to extract the url, you can use this:

var regexpmatch = mailmsg.match(/https:\/\/[^\s]{1,}/gm)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM