use strict;
my $str = '// valid addresses
rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn
r9kiSEUEw6iSCNksDVKf9k3AyxjW3r1qPf
rs2qdz5stxyWeMk6sNz5mLY6h5xxPYNJ8u
rfe8yiZUymRPx35BEwGjhfkaLmgNsTytxT
rPE9dw1gR8ravY2o25zudXmj2L28UTNt4D
r9vbV3EHvXWjSkeQ6CAcYVPGeq7TuiXY2X
// invalid addresses (with O, I, l or 0)
rPE9dw1gR8ravY2o25zudXmj2L20UTNt4D
r9vbV3EHvXWjSkeQ6CAcYVPGel7TuiXY2X
r9vbV3EHvXWjSkeQ6CAcYVPGeqOTuiXY2X
r9vbV3EHvXWjSkeQ6CAcYVPGeqITuiXY2X
';
my $regex = qr/^([r])([1-9A-HJ-NP-Za-km-z]{24,34})$/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