const regex = /\[.*?\)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\[.*?\\)', 'g')
const str = `Steps:\\n\\n[Step as , asdasd . sd32 'd](http://dev.nzfood-site.wn.bauer-media.net.au/silver-fern-farms-competition-21001) 1 Preheat oven to 120°C. Arrange six 1 1/2-cup ramekins in large baking dish lined [with](http://dev.nzfood-site.wn.bauer-media.net.au/silver-fern-farms-competition-21001) a cloth. \\nStep 2 In a medium saucepan, combine cream and vanilla. Place over medium heat and bring to almost boiling point. \\nStep 3 Meanwhile, in a bowl, whisk yolks and sugar together until thick and pale. Gradually pour in hot cream mixture, whisking constantly. \\nStep 4 Return mixture to clean saucepan. Cook on low heat 10-12 minutes, stirring constantly until thick enough to just coat the back of a wooden spoon (be careful not to overheat or mixture will curdle). \\nStep 5 Divide custard between ramekins. Pour boiling water into baking dish to come halfway up sides of ramekins. Bake 20-25 minutes until almost set and slightly wobbly in centre. Remove ramekins. \\nStep 6 Cool completely in fridge. Just before serving, sprinkle custards with an even layer of raw sugar. Using a kitchen blowtorch, drag the flame back and forth over the sugar until caramelised.`;
// 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