use strict;
my $str = 'ewd1 serpent 0 n ne o u w nw swamp
bats 0 n ne o u w nw swamp
undead 0 n ne o u w nw swamp
n river2 n ne o u
1002 e d
n <ewd8 ewd9 ewd2> se
n ewd9 s
n ewd2 sw
n rough w nw swamp
ewd2 serpent 0 w nw n swamp
bats 0 w nw n swamp
undead 0 w nw n swamp
n rough w nw n swamp
n <ewd1 ewd9 ewd10> ne o
n ewd9 e
n ewd10 se
n ewd4 s
n ewd3 sw';
my $regex = qr/^\h*(<[^>]*>|\S+)\h+(.*?)\h+(<[^>]*>|\S+)\h*$/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