这是来自 Yape::Regex::Explain 的解释
The regular expression:
(?-imsx:^.*(youtu.be/|v/|u/\w/|embed/|watch\?v=|\&v=)([^#\&\?]*).*)
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
youtu 'youtu'
----------------------------------------------------------------------
. any character except \n
----------------------------------------------------------------------
be/ 'be/'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
v/ 'v/'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
u/ 'u/'
----------------------------------------------------------------------
\w word characters (a-z, A-Z, 0-9, _)
----------------------------------------------------------------------
/ '/'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
embed/ 'embed/'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
watch 'watch'
----------------------------------------------------------------------
\? '?'
----------------------------------------------------------------------
v= 'v='
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
\& '&'
----------------------------------------------------------------------
v= 'v='
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
( group and capture to \2:
----------------------------------------------------------------------
[^#\&\?]* any character except: '#', '\&', '\?' (0
or more times (matching the most amount
possible))
----------------------------------------------------------------------
) end of \2
----------------------------------------------------------------------
.* any character except \n (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------