const regex = /(?i)<img[^>]+? src\s*?=\s*?"(.*?\?contextId.*?)"[^\/]+?\/>/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?i)<img[^>]+? src\\s*?=\\s*?"(.*?\\?contextId.*?)"[^\\\/]+?\\\/>', 'gm')
const str = `<img xmlns="http://www.w3.org/1999/xhtml" src="http://10.206.38.34:8080/resource/resources/aktuelle_Ressourcen/eService/Bilder/uebersicht-router.png?contextId=eservice_1.0.0.qualifier" alt="Bild Übersicht Router" title="Übersicht Router" />
<p> sdfs </p>
<img xmlns="http://www.w3.org/1999/xhtml" src="http://localhost:8080/resource/carl/eService/rain/apple.png?contextId=eservice_aaa" alt="Communicator" title="Super Robot" />
`;
// 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