use strict;
my $str = 'r Tor4ever AAcif1htILdru0BO0qX7OwGVhAU oHlbWBdaN3+QSleqBVL9/yAdcRs 2014-07-31 21:42:43
s Exit Fast Guard HSDir Running V2Dir Valid
v Tor 0.2.4.21
w Bandwidth=231
p reject 25,119,135-139,445,563,1214,4661-4666,6346-6429,6699,6881-6999
r Tornin AA8YrCza5McQugiY3J4h5y4BF9g vNRd1kyQ0i9UsVwYq5YFPHJi3jw 2014-08-01 00:26:18
s Fast Guard HSDir Named Running Stable V2Dir Valid
v Tor 0.2.4.23
w Bandwidth=713
p reject 1-65535';
my $regex = qr/^r\s(?P<nickname>\b\S+\b).*\n
^s\b.*?(?P<type>\bGuard\b).*\n
^v.*\n
^w\s.*?(?P<bandwidth>\b[0-9]+\b)/mxp;
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