const regex = new RegExp('([M,F]\\/\\d{2}\\/((\\d{1}((\\\\')|(\\’))?(([0,2-9]|1[0-1]?)((\\")|(\\\\'\\\\')|(\\”))?)?)|\\d{1,3}cm|[1-2]m(\\d{1,2}(cm)?)?)\\s?\\[\\d{2,3}\\s?(lbs|kg)\\s?to\\s?\\d{2,3}\\s?(lbs|kg)\\]\\s?\\(((\\d{1,2}\\s?years?)|(([2-9]|1[0-1]?)\\s?months?)|(\\d{1,2}\\s?years?(\\;|\\,)?\\s?([0,2-9]|1[0-1]?)\\s?months?)|(([2-9]|1[0-1]?)\\s?weeks?))\\)\\s?(\\s?\\+\\s?\\(([DSBO]{1}:\\s?(\\d{2,3})\\s?(lbs|kg)(\\;|\\,))?\\s?([DSBO]{1}:\\s?(\\d{2,3})\\s?(lbs|kg)(\\;|\\,))?\\s?([DSBO]{1}:\\s?(\\d{2,3})\\s?(lbs|kg)(\\;|\\,))?\\s?[DSBO]{1}:\\s?(\\d{2,3})\\s?(lbs|kg)\\))?.*)|(^\\[Meta\\].*)', 'gm')
const str = `
M/20/5'10" [150lbs to 180lbs] (2 years; 6 months) + (B: 300lbs; S: 410lbs; D: 480lbs)
F/26/5'2" [52kg to 59kg] (5 years)
M/35/6'3" [203lbs to 175lbs] (7 months) - Additional comments here
M/20/5'10" [150lbs to 180lbs] (2 years; 6 months) + (B: 300lbs; S: 410lbs; D: 480lbs) `;
// 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