Regex to get the words between @ and .com in the mail address
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2024 01:01 AM
Hi All,
Please help in writing a regex value to get the words between @ and .com in the mail address .
var email = "user@example.com";
var match = email.match(/(?<=@)[^\.]+(?=\.com)/);
if (match) {
gs.info("Matched word: " + match[0]);
}
After running the code i should get the value example . Thanks in advance

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2024 01:45 AM
@kali Unfortunately, the Look behind (?<) is not supported in Regex implementation of Javascript. Please refer to this thread https://www.servicenow.com/community/developer-forum/regexp-lookbehind-invalid-quantifier-quot-quot-... to know more about it.
Your best bet would to use split as follows.
var email = "user@example.com";
var match = email.split('@')[1].split('.')[0];
if (match) {
gs.info("Matched word: " + match);
}
Hope this helps.