const regex = /(\d){1}\t\t(\d){1,3}\%\s\t(\d){1}\t(\d){1,3}\%/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\d){1}\\t\\t(\\d){1,3}\\%\\s\\t(\\d){1}\\t(\\d){1,3}\\%', 'g')
const str = `Current car character
Power Handling Acceleration
102 107 104
Car character points history
Car part Level Action Wear New level New wear
Chassis: 6 96% 6 96%
Engine: 7 100% 7 100%
Front wing: 8 70% 8 70%
Rear wing: 8 75% 8 75%
Underbody: 8 63% 8 63%
Sidepods: 8 91% 8 91%
Cooling: 8 80% 8 80%
Gearbox: 7 82% 7 82%
Brakes: 9 25% 9 25%
Suspension: 8 94% 8 94%
Electronics: 8 78% 8 78%
(\\d){1}\\t\\t(\\d){1,3}\\%\\s\\t(\\d){1}\\t(\\d){1,3}\\%`;
// 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