Is there a way to use the not (^) character in a regex for multiple characters?

I want to create a Regex template that matches all relative patches.

What I want to combine:

img src = "image.png"
img src = "http_image.png"

What I do not want to match:

img src = "http: //example/image.png"

I tried matching with these patterns, but none of them work:

\ src = "[^ http: //] \
\ src = "^ (http: //) \
\ src = "[^ h] [^ t] [^ t] [^ p] [^:] [^ /] [^ /] \
\ src = "([^ h] [^ t] [^ t] [^ p] [^:] [^ /] [^ /]) \

I pulled <> from the img tag, because otherwise I could not write it as code.
The src attribute will always be formatted with double quotes ("), not single quotes (').
It will always contain the source" http ", not" https "or others.

+3
source share
1 answer

A way to solve this is to use a negative statement to predict:

^img src="(?!http:\/\/\S+).*"$

Ruble link

^                  : Start anchor
img src="          : Literal img src="
(?!http:\/\/\S+)   : To ensure the string following " is not a URL
.*                 : Anything else is allowed
"                  : Literal "
$                  : End anchor
+9
source

Source: https://habr.com/ru/post/1795671/


All Articles