igorGIS
igorGIS

Reputation: 1946

Regex Negative lookahead not work as expected

I have a following text:

 #arkLogo {
            background-image: url("static/images/arklogo.png");
        }   

And i've create a regex to extract all urls, like

static/images/arklogo.png

My regex is:

(?!url\s*\()("|').*(?=("|')\))

But it matches url with first quote like this:

"static/images/arklogo.png

I try to move scope of lookahead to capture this quote like this

(?!url\s*\(("|')).*(?=("|')\))

But in this case it mathes entire line

background-image: url("static/images/arklogo.png");

I found a solution, i just need to use positive lookbehind, like this:

(?<=url\s*\(("|')).*(?=("|')\))

Upvotes: 1

Views: 70

Answers (1)

igorGIS
igorGIS

Reputation: 1946

I found a solution, i just need to use positive lookbehind, like this:

(?<=url\s*\(("|')).*(?=("|')\))

Upvotes: 1

Related Questions