with javascript regex I´m trying to get the image name and extension as capture group of css properties.
Requirements
- starting with url
- followed by brackets
- inside brackets optional quotes
- location can have path information
- ending with jpeg or jpg or gif or png
Example:
behavior: url(#default#VML); -> ignored wrong ending
background-image: url(dog.ttf); -> ignored wrong ending
background-image: url('cat.png'); -> cat.png
background-image: url(bird.gif); -> bird.gif
background-image: url('../monkey.png'); -> monkey.png
background-image: url('../../rab$bit.png'); -> rab$bit.png
background-image: url('../animal/cow.jpg'); -> cow.jpg
This is what I have so far:
url(?:\(\"|\(\'|\(\/?.*\/|\()(\.+)?(\/.*\/)?(\w*)+(.png|.jpg|.gif|.jpeg)
https://regex101.com/r/3mMdTI/6
Unfortunately due to the '\w' group this breaks when a filename has digits or characters like $. Can one suggest a better solution?

/wyou can just use[^\'\"](negated set of single- and doublequotes to match all but the end