Regular Expressions 101

Save & Share

  • Save Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s

Flavor

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

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
(?:https?:\/\/)?(?:www.|web.|m.)?(?:facebook|fb).com\/(?:video.php\?v=\/?|\?v=\/?|watch\/\?v=\/?|watch\/\?v=\/?)|\S+\/videos\/?
/
gm
1st Alternative
(?:https?:\/\/)?(?:www.|web.|m.)?(?:facebook|fb).com\/(?:video.php\?v=\/?|\?v=\/?|watch\/\?v=\/?|watch\/\?v=\/?)
Non-capturing group
(?:https?:\/\/)?
? 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)
s
matches the character s with index 11510 (7316 or 1638) literally (case sensitive)
: matches the character : with index 5810 (3A16 or 728) 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
(?:www.|web.|m.)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
www.
www
matches the characters www literally (case sensitive)
. matches any character (except for line terminators)
2nd Alternative
web.
web
matches the characters web literally (case sensitive)
. matches any character (except for line terminators)
3rd Alternative
m.
m matches the character m with index 10910 (6D16 or 1558) literally (case sensitive)
. matches any character (except for line terminators)
Non-capturing group
(?:facebook|fb)
1st Alternative
facebook
facebook
matches the characters facebook literally (case sensitive)
2nd Alternative
fb
fb
matches the characters fb literally (case sensitive)
. matches any character (except for line terminators)
com
matches the characters com literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
Non-capturing group
(?:video.php\?v=\/?|\?v=\/?|watch\/\?v=\/?|watch\/\?v=\/?)
1st Alternative
video.php\?v=\/?
video
matches the characters video literally (case sensitive)
. matches any character (except for line terminators)
php
matches the characters php literally (case sensitive)
\? matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
v=
matches the characters v= literally (case sensitive)
\/
matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
2nd Alternative
\?v=\/?
\? matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
v=
matches the characters v= literally (case sensitive)
\/
matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
3rd Alternative
watch\/\?v=\/?
watch
matches the characters watch literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\? matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
v=
matches the characters v= literally (case sensitive)
\/
matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
4th Alternative
watch\/\?v=\/?
watch
matches the characters watch literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
\? matches the character ? with index 6310 (3F16 or 778) literally (case sensitive)
v=
matches the characters v= literally (case sensitive)
\/
matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
2nd Alternative
\S+\/videos\/?
\S
matches any non-whitespace character (equivalent to [^\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
videos
matches the characters videos literally (case sensitive)
\/
matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gm

Test String

Code Generator

Generated Code

Loading code sample...
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report.
For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php