use strict;
my $str = 'frankp@gmail.com
shannon.eee@gmail.com
franks&shannon@gmail.com
frank%ddd@gmail.com
frank@gmail$.com
frank@gmail_gmail.com
frank@gmail.research.com
joe@ggg.gg.cccc.com
joe..joe@gmail.com
/
https://stackoverflow.com/questions/5174171/fix-regular-expression-for-emails-to-not-allow-consecutive-periods/5174201#5174201
*To avoid matching two consecutive dots you can add a negative lookahead at the beginning of your regular expression:
/^(?!.*\\.{2})[a-z0-9etc...
------------
It will fail to match if there are two consecutive periods anywhere in the string and it doesn\'t require any other modifications to your original regular expression.
However it seems a bad idea as your regular expression isn\'t correct in the first place. If you insist on using regular expressions to validate email addresses, try this:
*/
wilson..gmail.com
wilson.gmail.com
^(?!.*\\.{2})/[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
';
my $regex = qr/[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?
/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html