Advertisement
aepokh

Email matching in perl

Nov 7th, 2011
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #!usr/bin/perl -w
  2. use strict;
  3.  
  4. foreach my $line (<DATA>) {
  5. print "$1\@$2\n" if $line =~
  6. m/([\w\._0-9]+)\@([\w0-9]+(\.[\w0-9]+)+)\.?/g;
  7. # after matching, $1 holds the email
  8. # and $2 holds the domain
  9. }
  10.  
  11. __DATA__
  12. Lorem ipsum dolor sit amet.
  13. This line does not contain an email.
  14. This line has an email: neo@matrix.com.
  15. Only "neo@matrix.com" is matched, even
  16. though there's a dot at the end.
  17. test.sample@gmail.com
  18. not_a_valid@email
  19. emails are matched@in.the middle
  20. __leading.underscores__@are.matched
  21. several.dots.will@still.match
  22. but only one dot can be in@the.domain.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement