const regex = /^(?:\d\h+|[\d.]*[A-Z][A-Z\d.]*\h+)*[A-Z]{3,}/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?:\\d\\h+|[\\d.]*[A-Z][A-Z\\d.]*\\h+)*[A-Z]{3,}', 'gm')
const str = `ID.4 ESTATE 109kW City Pure 52kWh 5dr Auto
XC40 DIESEL ESTATE 2.0 D4 [190] Inscription Pro 5dr AWD Gea+
RAPID DIESEL HATCHBACK 1.6 TDI CR Elegance 5dr
MODEL 3 120kW LONG RANGE AWD
V40 DIESEL HATCHBACK D2 [120] Momentum 5dr Geartronic
V60 DIESEL SPORTSWAGON 2.0 D4 [190] R DESIGN Plus 5dr Auto
X3 ESTATE xDrive M40i 5dr Auto
C CLASS DIESEL SALOON C250 BlueTEC SE 4dr Auto
A CLASS DIESEL HATCHBACK A180d Sport Executive 5dr Auto
2 SERIES COUPE 218i Sport 2dr [Nav] Step Auto
HILUX SPECIAL EDITIONS Invincible X Ltd Ed D/Cab P/Up 2.4 D+
C3 PICASSO 1.6 BlueHDi Platinum 5dr
C3 HATCHBACK 1.2 PureTech 82 Flair 5dr
XC40 DIESEL ESTATE XC40
1`;
// 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