use strict;
my $str = '123456789
123ABCDEF
123ABDdef
123ABCdeF$
123ABCdeF_
123ABCdeF$ 1234
123ABCdeF$ 1ABC
123ABCdeF$ 1Abc
123ABCdeF$ 1Ab$
123acC&
123acC &
test@123
test_@123A
test_@123A sdf
_123456789
_123ABCDEF
_123ABDdef
_123ABD def
1Ab2
1Ab!
!123
!ABC
!1Ab
123_
1AB_
1Ab_
';
my $regex = qr/^(?=.*[\d])(?=.*[a-z])(?=.*[A-Z])(?=.*([^\w\s]|[_]))(\S+)$/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