Because of a linting issue (line too long), I'm trying to break up a regex into two lines. Given the function
function isValidEmail(email) {
const pattern = new RegExp(`/^(?!.*[._@]{2})[a-z0-9\u00C0-\u00D6\u00D9-\u00F6\u00F9-\u00FC][a-z0-9_.
\u00C0-\u00D6\u00D9-\u00F6\u00F9-\u00FC]*@\w+(\.\w+)?(\.[a-z]{2,3})?\.[a-z]{2,3}$/i`);
return pattern.test(email.trim());
}
My solution was to use backticks, but it seems that converting a RegExp into a String isn't as straightforward as it seems in Javascript (to be clear, I'm writing typescript and having it transpiled to Javascript.) When I debug the resulting javascript file, the pattern variable becomes
/\/^(?!.*[._@]{2})[a-z0-9À-ÖÙ-öù-ü][a-z0-9_.
À-ÖÙ-öù-ü]*@w+(.w+)?(.[a-z]{2,3})?.[a-z]{2,3}$\/i/
I'm not sure what's happening the the RegExp, but I haven't been able to get my email RegExp to work aftre breaking it into multiple lines. What is happening in the background, and how do I solve for this?