ehime
ehime

Reputation: 8405

Regular expression needs to NOT match if href or src is preceeded by a dot

The title pretty much explains it, I keep matching ga.src when I don't want to be, otherwise this is a great solution. Could someone tell me what is wrong?

Not working

~(?!.)\b(?:href|src)\s*=\s*(["\']?+)\K(?:/(?!/)|(?=[\s>]|\1))~i

Works but matches .src .href

~\b(?:href|src)\s*=\s*(["\']?+)\K(?:/(?!/)|(?=[\s>]|\1))~i

Upvotes: 2

Views: 67

Answers (1)

HamZa
HamZa

Reputation: 14931

(?!.) is a negative lookahead which checks if there is no character ahead (except for newline), which doesn't make sense. You want a lookbehind and the dot should be escaped (?<!\.).

Read about lookarounds on www.regular-expressions.info

Upvotes: 2

Related Questions