That's a really messed up regex. What are you trying to achieve exactly? It looks like if the URL doesn't start with http or https you want to add the domain? If so, you're quite a bit off:
$string = preg_replace('/src=(\'|")?(?!htts?:)/i', 'src="http://domain.com/');
should be a lot closer to the mark.
What does this regex do? It looks for:
src=
- optionally followed by either
'
or "
- not followed by
http:
or https:
- all done case insensitive
Note: {?!...)
is called a negative lookahead and is one example of a zero-width assertion. "Zero-width" here means that it doesn't consume any of the input. In this case it means "not followed by ...".
What does your regex do? It looks for:
src=
- one or more
'
or "
characters
- any one character that isn't any of
(http:|https:)
(that's what the [^...]
construct means)
- all case insensitive
Note:
[^(http:|https:)]
is equivalent to:
[^():https]
meaning any character that is not one of those characters.