Answer the question
In order to leave comments, you need to log in
Strange "negative look ahead" behavior. RegExp example inside
I can't understand the reason. Tell me please. Task: find in the CSS file all the background properties that have a relative path to the image in the url and change it to an absolute one. Url can be enclosed in either single or double quotes. A url starting with a slash is considered absolute.
Here is the regular season:
url\(("|')?(?!\w*?:?//|/)(.+?)("|')?\)
And here is the result:
Example No. 1
.class {
background: url(images/bubbles.png) top repeat-x;
}
.class {
background: url(/images/bubbles.png) top repeat-x;
background: url(http://images/bubbles.png) top repeat-x;
}
.class {
background: url('images/bubbles.png') top repeat-x;
}
.class {
background: url('http://images/bubbles.png') top repeat-x;
}
Answer the question
In order to leave comments, you need to log in
I advise you to make the regular expression more stable and reliable, instead of a dot, explicitly set the list of characters allowed in the url:
[
^'"\\s]+?
Question: why is the first group of matches empty, the second contains a quote and a path, while the third one works correctly?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question