const regex = /\(seção: (?'secao'\d+), aptos: (?'aptos'\d+)\)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('\\(seção: (?\'secao\'\\d+), aptos: (?\'aptos\'\\d+)\\)', 'gm')
const str = `(seção: 509, aptos: 121)
(seção: 517, aptos: 118)
(seção: 327, aptos: 89), (seção: 328, aptos: 90)
(seção: 371, aptos: 89), (seção: 520, aptos: 53)
(seção: 331, aptos: 111), (seção: 332, aptos: 111), (seção: 334, aptos: 111)
`;
// 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