You cannot use ?
quantifier in MySQL regex as the syntax is POSIX-based. Still, you can use *
to match 0 or more characters. Also, \b
in MySQL regex should be replaced with [[:<:]]
(since this matches at the beginning of a word).
Thus, I suggest using
[[:<:]](([a-zA-Z0-9-]+:\/\/*|www[.])[^ ()<>]+(\([a-zA-Z0-9_]+\)|([^ [:punct:]]|\/)))
I am expanding \w
to [a-zA-Z0-9_]
as it is exactly what \w
is. Instead of \s
, I am using a literal space. Instead of \d
, I am using [0-9]
. This is done for readability and better compatibility. If \w
, \d
and \s
work for you, you can use them, but I do not see them among the supported entities in POSIX specs.
Also, instead of literal space, you could use [:space:]
, it matches space, tab, newline, and carriage return. Instead of [a-zA-Z]
you can use [:alpha:]
, and instead of [0-9]
, you can use [:digit:]
. Please also check this:
[[:<:]](([[:alpha:][:digit:]-]+:\/\/*|www[.])[^[:space:]()<>]+(\([[:alpha:][:digit:]_]+\)|([^[:space:][:punct:]]|\/)))