I wrote following function in order to parse available image sizes inside srcset
attribute for each img
element and return it as array.
Everything works as expected when the debug mode is on, but once I disable the debug mode, the app would crash and throw following error:
Error: invalid regular expression invalid group specifier name
export function srcsetParser(htmlString) {
let result = [];
let images = htmlString.match(/<img\s+[^>]*srcset="([^"]*)"[^>]*>/g); // Finding img tags inside html string
images && images.forEach(image => {
let srcsets = image.match(/(?<=srcset=").+?(?=\")/g); //Select srcset value
var urls = srcsets[0].split(", ");
urls.forEach(url => {
let temp = url.split(" ");
result.push(temp[0]);
});
});
return result;
}
Any idea what's wrong with the regex and why is it so only when debug mode is off ?
Thanks