$string='I want to be transformed to a proper link: http://www.google.com But please leave me alone (<a href="https://www.google.com">https://www.google.com</a>).';
$regex='~ # delimiter
(?<![">]) # a neg. lookbehind
https?://\S+ # http:// or https:// followed by not a whitespace
I want to be transformed to a proper link: <a href='http://www.google.com'>http://www.google.com</a> But please leave me alone (<a href="https://www.google.com">https://www.google.com</a>).