I wrote a regex that should match email addresses and it works great here https://regex101.com/r/nBl4Wc/2, but when I try to execute it using JavaScript
it gives this error:
SyntaxError: Invalid regular expression Unmatched ')'
This is my code:
var myString = 'email_address=test.user@gmail.com';
var regex = new RegExp('(?:[a-z0-9+_~-]+(?:\.[a-z0-9+_~-]+)*)@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?|[a-z0-9-]*[a-z0-9]:+)\]');
var matched = myString.match(regex);
Why that regex isn't working with JavaScript
?
I saw that there are other questions similar to this one, but I couldn't find a solution that would fix this issue...