Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # How to Find or Validate an Email Address
- ## REGULAR EXPRESSION
- /((?:[\.\-\_\w\d])+\@(?:\w|\d)+(?:\.(?:\w)+)+)/gi
- ## EXPLANATION
- * /((?:[\.\-\_\w\d])+\@(?:\w|\d)+(?:\.(?:\w)+)+)/gi
- * 1st Capturing group ((?:[\.\-\_\w\d])+\@(?:\w|\d)+(?:\.(?:\w)+)+)
- * (?:[\.\-\_\w\d])+ Non-capturing group
- Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
- * [\.\-\_\w\d] match a single character present in the list below
- \. matches the character . literally
- \- matches the character - literally
- \_ matches the character _ literally
- \w match any word character [a-zA-Z0-9_]
- \d match a digit [0-9]
- \@ matches the character @ literally
- * (?:\w|\d)+ Non-capturing group
- Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
- * 1st Alternative: \w
- \w match any word character [a-zA-Z0-9_]
- * 2nd Alternative: \d
- \d match a digit [0-9]
- * (?:\.(?:\w)+)+ Non-capturing group
- Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
- \. matches the character . literally
- * (?:\w)+ Non-capturing group
- Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
- \w match any word character [a-zA-Z0-9_]
- * g modifier: global. All matches (don't return on first match)
- * i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
- ## JAVASCRIPT EXAMPLE
- var re = /((?:[\.\-\_\w\d])+\@(?:\w|\d)+(?:\.(?:\w)+)+)/gi;
- var str = 'correo de facebook agreguenme halcon0324@hotmail.com.mx =)\ningeni-ero.ajrr@hotmail.com\nhola, espero pertenecer a la comunidad. nbreuerp@hotmail.com';
- var m;
- while ((m = re.exec(str)) !== null) {
- if (m.index === re.lastIndex) {
- re.lastIndex++;
- }
- // View your result using the m-variable.
- // eg m[0] etc.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement