I’ve tested my regex on Regex testers and it worked, but I didn’t get it to work on my code.
var mail = "chdelfosse@gmail.com";
var regExp = new RegExp("@(.*?)\.");
document.write(regExp.exec(mail)) ;
I get this result :
@g,
I tried to add a backslash before the dot, and I got this :
@gmail.,gmail
I also wanted to remove the “@” and the “.” from the email, so I tried to use ” (?:@) “, but I didn’t get it to work (on Regex testers).
It’s my first time trying to use Regex, and I don’t get it.
Why is there a comma ?
You can use this regex to get the domain name:
Live DEMO