const regex = /([\S]*)[\s]+([\S]*[\s]+[\S]*)[\s]+([0-9]{1,2})\%/i;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('([\\S]*)[\\s]+([\\S]*[\\s]+[\\S]*)[\\s]+([0-9]{1,2})\\%', 'i')
const str = `RY4 Asian Flavor 10-15%
RY4 Double Flavor 5%-15%
Smooth Flavor 2 drops per 5 ml
Spearmint Flavor <5% Very Strong
Strawberries and Cream Flavor 10-12%
Strawberry Flavor 3%-15%
Strawberry Kiwi 20% 1/5
Strawberry Ripe 15%
Sweet Cream Flavor 5-10% 4/5 recommended for combining fake butter taste
Sweet Tart: 10% 5/5 Tastes more like Smarties
Sweetener 2%-6%
Tangerine Flavor (oil based) 1-5% 5/5
Tiramisu Flavor 2-5% VERY strong
Toasted Almond Flavor 15%`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
if ((m = regex.exec(str)) !== null) {
// 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