I am currently working on a project where I need to match specific html tags and replace them by some others.
I am using Javascript in order to do so, and the code looks like :
// html to update
html = '<div class="page-embed"><article><iframe src="https://alink" width="100%"></iframe></article></div>';
// regex that will match the specific "<div class="page-embed">...<iframe src="https://alink"></iframe>...</div>
const regexIframeInsideDiv = /<\s*div\s*class="page-embed"[^>]*>.*?<\s*iframe[^>]*\s*src="(.*?)"\s*><\s*\/\s*iframe\s*>.*?<\s*\/\s*div\s*>/g;
html = html.replace(regexIframeInsideDiv, (_match, src) => {
console.log(src);
return `<oembed>${src}</oembed>`;
});
I use the () tool to get what is inside the source attribute as follow :
src="(.*?)"
Here is the problem :
If I run the code, the console will log :
https://alink" width="100%
where it should log :
https://alink
I might be missing something, like escape string or an error anything else.. but I don't know what.
Here is the expected behaviour :https://regexr.com/4tbj6
Thank you !