user3835327
user3835327

Reputation: 1204

javascript replace string with exact match

i have bulk of email address in textarea '[email protected]@[email protected]@[email protected]@hotmail.com'

what i want to do is add 'comma space' behind of .com / .com.my

expected result after onblur function in textarea: `[email protected], [email protected], [email protected], [email protected], [email protected], [email protected]

what i have tried.

b = value.split('.com.my').join('.com.my, ');
b = value.split('.com').join('.com, ');

problem : it will replace all '.com' to '.com, ' even with '.com.my'

Upvotes: 0

Views: 101

Answers (1)

Ravi Theja
Ravi Theja

Reputation: 3401

var value = "[email protected]@[email protected]@[email protected]@hotmail.com";
value = value.replace(/(.com(.my)?)/gm, '$1, ');
console.log(value.substring(0, value.length - 2));

Upvotes: 3

Related Questions