aepokh

Email matching in perl

Nov 7th, 2011
91
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: [email protected].
  15. Only "[email protected]" is matched, even
  16. though there's a dot at the end.
  17. not_a_valid@email
  18. emails are [email protected] middle
  19. but only one dot can be [email protected].
Advertisement
Add Comment
Please, Sign In to add comment