DontVoteMeDown
DontVoteMeDown

Reputation: 21465

.NET Regex look behind issue

I have the following regex:

(?<=(url\(.+))\)

It supposed to match the closing ) of url(. It works. But if I have any other ) after the first one, in the same line, it matches too. Example:

      url(abc) format(def)
matches this ^  and this ^

I would like to know what can be done to match only the ) char that closes url(.

Upvotes: 0

Views: 47

Answers (1)

dee-see
dee-see

Reputation: 24078

Match for characters that are not ) instead of any character in your look-behind.

(?<=(url\([^)]+))\)

Your original regex finds a ) preceded by the string abc) format(def which is itself preceded by url( so the second ) was also valid.

Upvotes: 4

Related Questions