const regex = new RegExp('^(?P<unit_type>SFS)(?P<unit_size>300|250|200)(?P<mounting_type>A|B)(?P<decompression_feature>0)(?P<sep_1>-)(?P<cracking_pressure>1)(?P<sep_2>-)(?P<unit_series>4X)(?P<sep_3>/)(?P<seal_material>|)(?P<additional_details>(.|[0-9])*)$', 'gm')
const str = `SFS300A0-1-4X/
SFS250A0-1-4X/
SFS200A0-1-4X/
SFS200B0-1-4X/
SFS250A0-1-4X/Q2TQ.G24
SFS250A0-1-4X/Q2TQ2G24
SFS200A0-1-4X/Q2TQ2G24
SFS300A0-1-4X/Q2TQ2G24
SFS250B0-1-4X/
`;
// 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