I am trying to change an HTML page that has inline styles, I want to make a regex expression that captures the background url and the selector, example:
<div>some html here</div>
<style>#some-selector {
padding-top: 408px;
}
#some-selector .bg {
background-image: url(www.some-url.com/some-image.jpg);
}
#some-selector {
background-position: 43% 97%;
}
what I want to capture here is #some-selector .bg
and www.some-url.com/some-image.jpg
, keep in mind that the HTML page is big, and the expression should be fast
I came up with this expr <style[\s\S]*?[>}\/\n](.*){[\s\S]*?background.*?url\((.*?)\)
but it's not working correctly, I know that I the first [\s\S]
should be greedy but when i remove the ?
it leads to catastrophic backtracking <style[\s\S]*[>}\/\n](.*){[\s\S]*?background.*?url\((.*?)\)
it does work on small strings but on the whole page it causes catastrophic backtracking, i've used regex101 to test it.
Any help is appreciated
Edit: here's an example https://regex101.com/r/ZMxOSz/1