preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches)
The |\s| in this regular () What does it mean? Does anyone know?
Reply content:
preg_match_all("#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i", $str, $matches)
The |\s| in this regular () What does it mean? Does anyone know?
I'll explain every part to the master.
#(^|\s|\()((http(s?)://)|(www\.))(\w+[^\s\)\<]+)#i
On both sides #
is the PCRE delimiter, and the last one i
indicates the case is ignored.
(^|\s|\()
The string begins with either a space separation or an opening parenthesis. This section is an unnamed grouping.
((http(s?)://)|(www\.))
Match http://
or https://
maybe www.
. This section is an unnamed grouping, which is divided into two unnamed groupings.
(\w+[^\s\)\<]+)
Match at least one alphanumeric number, and then match at least one character that is not a space, a closing parenthesis, or a left angle bracket. Here is another unnamed grouping.
End.
Recommended two debug regular sites:
- Debuggex interface, powerful, support multi-lingual regular
- Regexper is better looking, only support JavaScript regular