const regex = /width=\"([^"]*)\"/mg;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('width=\\"([^"]*)\\"', 'mg')
const str = `<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2599.1307619404383!2d8.161241415866494!3d49.34967357394241!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x479648efa698cf4d%3A0xb771157caba628a8!2sMennoniten%20Branchweilerhof!5e0!3m2!1sde!2sde!4v1590230850775!5m2!1sde!2sde" width="600" height="450" frameborder="0" allowfullscreen="allowfullscreen" aria-hidden="false" tabindex="0" style="border: 0px;"></iframe>`;
// 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