getting string between two characters.

Nitesh Balusu
Giga Guru

Hello,

I have a long string that looks like this, i need to get the email address between < abc@example.com>

Can someone help me with this?

 

var a='abc, def<abc.def@example.com>; ghj, qwe <ghe.qwe@example.com>; bnm, jkl <bnm.jlk@example.com>;';

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Nitesh,

So you need to get all email addresses between < and >

Sample script here:

var str = 'abc, def<abc.def@example.com>; ghj, qwe <ghe.qwe@example.com>; bnm, jkl <bnm.jlk@example.com>;';
var split1 = str.split(";");

var emailAddressArray = [];
for(var i=0;i<split1.length-1;i++){

var initialString = split1[i];

var emailAddress  = initialString.substring(initialString.indexOf("<") + 1, initialString.indexOf(">"));

emailAddressArray.push(emailAddress.toString());

}

gs.print('Email Address Array is: ' + emailAddressArray);

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Nitesh,

So you need to get all email addresses between < and >

Sample script here:

var str = 'abc, def<abc.def@example.com>; ghj, qwe <ghe.qwe@example.com>; bnm, jkl <bnm.jlk@example.com>;';
var split1 = str.split(";");

var emailAddressArray = [];
for(var i=0;i<split1.length-1;i++){

var initialString = split1[i];

var emailAddress  = initialString.substring(initialString.indexOf("<") + 1, initialString.indexOf(">"));

emailAddressArray.push(emailAddress.toString());

}

gs.print('Email Address Array is: ' + emailAddressArray);

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Awesome, thanks!