use strict;
my $str = '15° 1\' 36.991" E
15° 2\' 21.421" E
15° 2\' 0.712" E
15° 2\' 45.181" E
15° 3\' 1.709" E
14° 58\' 24.822" E
14° 58\' 39.840" E
14° 58\' 26.234" E
14° 58\' 45.145" E
15° 0\' 14.01" E
15° 0\' 11.460" E
15° 0\' 7.928" E
15° 1\' 53.693" S
15° 2\' 24.699" E
15° 2\' 45.547" E
15° 2\' 12.837" E
15° 2\' 43.594" E
15° 2\' 31.644" E
15° 3\' 1.059" E
14° 59\' 46.315" E
14° 59\' 31.694" E
15° 2\' 41.057" E
14° 58\' 40.068" E
36°57\'9" N';
my $regex = qr/(\d+)\s?°\s?(\d+)\s?'\s?(\d+\.?\,?\d*?)"\s?(N|W|S|E)/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