Advertisement
vladovip

RegExp_Extract Emails_JS FUND

Sep 4th, 2022
1,467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     const regEx = /(\s|^)(?<email>(?<user>[0-9a-zA-Z][.\-_0-9a-zA-Z]*[0-9a-zA-Z])@(?<host>([a-zA-Z]+(-+[a-zA-Z]+)?)\.([a-zA-Z]+(-+[a-zA-Z]+)?)(\.([a-zA-Z]+(-+[a-zA-Z]+)?))?))/g
  3.     let emails = [];
  4.     let result = regEx.exec(input);
  5.  
  6.     while (result !== null) {
  7.         emails.push(result.groups.email);
  8.         result = regEx.exec(input);
  9.     }
  10.  
  11.     for (const email of emails) {
  12.         console.log(email);
  13.     }
  14. }
  15.  
  16. solve ('Please contact us at: support@github.com.');
  17. solve ('Just send email to s.miller@mit.edu and j.hopking@york.ac.uk for more information.');
  18. solve ('Many users @ SoftUni confuse email addresses. We @ Softuni.BG provide high-quality training @ home or @ class. –- steve.parker@softuni.de.');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement