This content originally appeared on DEV Community and was authored by 101samovar
There is a string that contains email addresses.
To get the email addresses we need the match method.
The match method with a regular expression pattern for email addresses.
This pattern suppose that the email address consists of login name, at-symbol and domain name.
Login name can be combined from letters in lower and upper case, digits and underscore symbol.
Domain name should consist of two parts separated with a dot symbol.
let string = 'manager: Smith@sm-domain.net; sales: Mak@sm-domain.net';
let emailList = string.match(/[\w]+@[\w\-]+\.[\w]{2,}/g);
console.log(emailList);
So we have got an array with email addresses from the string.
I hope you found this article useful, if you need any help please let me know in the comment section.
? See you next time. Have a nice day!
Subscribe to our channel:
https://www.youtube.com/c/Samovar101
This content originally appeared on DEV Community and was authored by 101samovar

101samovar | Sciencx (2021-09-22T06:05:22+00:00) How to extract email-address from a string?. Retrieved from https://www.scien.cx/2021/09/22/how-to-extract-email-address-from-a-string/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.