简体   繁体   中英

unable to extract substring from gmail body using google app script

I am novice to google app script. can you please help to extract string from the below text?

Advertiser Campaign Walgreens FY20 RAD Conversion

I want to extract campaign name that is "FY20 RAD Conversion". Below I have used the code to extract but I have failed as if i use split advertiser name walgreens may appear in mail body as well. But i want o extract this instance. can some on help me? below is my code

  var cmpname = message[t][x].getPlainBody().split('Walgreens')[1].split("\n")[0];

my sample message is

Dear MediaCom_Walgreens team, Your report on the following campaign with Integral is ready for download: Advertiser Campaign Walgreens FY20 RAD Conversion Acq

and my desired text to extract from message is FY20 RAD Conversion Acq

does some one can help??

function xtractString(s) {
  var s=s||'Dear MediaCom_Walgreens team, Your report on the following campaign with Integral is ready for download: Advertiser Campaign Walgreens FY20 RAD Conversion Acq.'
  Logger.log(s.slice(-s.split("").reverse().join("").indexOf('Walgreens'.split("").reverse().join("")),-1));
  //[20-05-18 13:56:45:821 MDT]  FY20 RAD Conversion Acq
}

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