const regex = /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)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('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)', 'gm')
const 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`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions