use strict;
my $str = '1) Subject: FW: NEFS 11 fish for lease
From: Claire Fitz-Gerald
Date: 11/15/2013 3:02 PM
NEFS 11 has the following fish for lease:
-GOM Cod up to 5,000 lbs (live wt) @ 1.40 lbs
-American Plaice 2,000 lbs .60 lbs or best offer
2) From: Claire Fitz-Gerald
Date: 9/5/2014 9:52 AM
Subject: NEFS 5 Available Fish
All,
NEFS 5 has the following fish available for lease/trade:
GB EAST cod: 954 lbs @ $0.83
GB EAST cod: 1,046 lbs to trade for 1,830 lbs GB WEST cod
GB blackback: 30,000 lbs @ $0.07
GOM blackback: 800 lbs @ $0.03
white hake: 6,322 lbs @ $0.13
pollock: 22,000 lbs @ $0.015
redfish: 14,000 lbs @ $0.015
GB yt: 1,873 lbs @ $1.13
GB yt: 5,127 lbs to trade for 10,254 lbs SNE yt';
my $regex = qr/Date: (?<date>\d{1,2}\/\d{1,2}\/\d{4} \d{1,2}:\d{1,2} [AP]M)|(?<sector>NEFS \d+)|^\s+(?!Date|Subject|NEFS|From)-?(?<fishes>\w[\w ]{0,15}(?=:| up|\d))|(?<weight>(\d+[,.])?\d+(?= lbs))|@ \$?(?<price>\d*.?\d*)(?!\s+lbs)/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