Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
(http(?: s) ?: \/\/(?:m.)?(?:www\.)?)?youtu(?:\.be\/|be\.com\/(?:watch\?(?:feature=youtu\.be\&)?v=|v\/|embed\/|user\/(?:[\w#]+\/)+))([^&#?\n]+)
/
1st Capturing Group
(http(?: s) ?: \/\/(?:m.)?(?:www\.)?)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
http
matches the characters http literally (case sensitive)
Non-capturing group
(?: s)
s
matches the characters s literally (case sensitive)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
:
matches the characters : literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
Non-capturing group
(?:m.)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
m matches the character m with index 10910 (6D16 or 1558) literally (case sensitive)
. matches any character (except for line terminators)
Non-capturing group
(?:www\.)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
www
matches the characters www literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
youtu
matches the characters youtu literally (case sensitive)
Non-capturing group
(?:\.be\/|be\.com\/(?:watch\?(?:feature=youtu\.be\&)?v=|v\/|embed\/|user\/(?:[\w#]+\/)+))
1st Alternative
\.be\/
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
be
matches the characters be literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
2nd Alternative
be\.com\/(?:watch\?(?:feature=youtu\.be\&)?v=|v\/|embed\/|user\/(?:[\w#]+\/)+)
be
matches the characters be literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
com
matches the characters com literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
Non-capturing group
(?:watch\?(?:feature=youtu\.be\&)?v=|v\/|embed\/|user\/(?:[\w#]+\/)+)
1st Alternative
watch\?(?:feature=youtu\.be\&)?v=
watch
matches the characters watch literally (case sensitive)
\? matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
Non-capturing group
(?:feature=youtu\.be\&)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
feature=youtu
matches the characters feature=youtu literally (case sensitive)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
be
matches the characters be literally (case sensitive)
\& matches the character & with index 3810 (2616 or 468) literally (case sensitive)
v=
matches the characters v= literally (case sensitive)
2nd Alternative
v\/
v matches the character v with index 11810 (7616 or 1668) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
3rd Alternative
embed\/
embed
matches the characters embed literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
4th Alternative
user\/(?:[\w#]+\/)+
user
matches the characters user literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
Non-capturing group
(?:[\w#]+\/)+
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[\w#]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\w matches any word character (equivalent to [a-zA-Z0-9_])
# matches the character # with index 3510 (2316 or 438) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
2nd Capturing Group
([^&#?\n]+)
Match a single character not present in the list below
[^&#?\n]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
&#?
matches a single character in the list &#? (case sensitive)
\n matches a line-feed (newline) character (ASCII 10)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/

Test String