Advertisement
Guest User

Untitled

a guest
Sep 26th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. # How to Find or Validate an Email Address
  2.  
  3. ## REGULAR EXPRESSION
  4.  
  5. /((?:[\.\-\_\w\d])+\@(?:\w|\d)+(?:\.(?:\w)+)+)/gi
  6.  
  7. ## EXPLANATION
  8.  
  9. * /((?:[\.\-\_\w\d])+\@(?:\w|\d)+(?:\.(?:\w)+)+)/gi
  10. * 1st Capturing group ((?:[\.\-\_\w\d])+\@(?:\w|\d)+(?:\.(?:\w)+)+)
  11. * (?:[\.\-\_\w\d])+ Non-capturing group
  12. Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
  13. * [\.\-\_\w\d] match a single character present in the list below
  14. \. matches the character . literally
  15. \- matches the character - literally
  16. \_ matches the character _ literally
  17. \w match any word character [a-zA-Z0-9_]
  18. \d match a digit [0-9]
  19. \@ matches the character @ literally
  20. * (?:\w|\d)+ Non-capturing group
  21. Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
  22. * 1st Alternative: \w
  23. \w match any word character [a-zA-Z0-9_]
  24. * 2nd Alternative: \d
  25. \d match a digit [0-9]
  26. * (?:\.(?:\w)+)+ Non-capturing group
  27. Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
  28. \. matches the character . literally
  29. * (?:\w)+ Non-capturing group
  30. Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
  31. \w match any word character [a-zA-Z0-9_]
  32. * g modifier: global. All matches (don't return on first match)
  33. * i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
  34.  
  35. ## JAVASCRIPT EXAMPLE
  36. var re = /((?:[\.\-\_\w\d])+\@(?:\w|\d)+(?:\.(?:\w)+)+)/gi;
  37. var str = 'correo de facebook agreguenme halcon0324@hotmail.com.mx =)\ningeni-ero.ajrr@hotmail.com\nhola, espero pertenecer a la comunidad. nbreuerp@hotmail.com';
  38. var m;
  39.  
  40. while ((m = re.exec(str)) !== null) {
  41. if (m.index === re.lastIndex) {
  42. re.lastIndex++;
  43. }
  44. // View your result using the m-variable.
  45. // eg m[0] etc.
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement