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
/
(?:musicdb|videodb|special):\/\/(?<Type>albums|tvshows|genres|masterprofile|artists)\/(?:titles\/)?(?<Identifier>[\w\d\-.]+)\/?(?<Season>\d+)?
/
gm
Non-capturing group
(?:musicdb|videodb|special)
1st Alternative
musicdb
musicdb
matches the characters musicdb literally (case sensitive)
2nd Alternative
videodb
videodb
matches the characters videodb literally (case sensitive)
3rd Alternative
special
special
matches the characters special 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)
Named Capture Group Type
(?<Type>albums|tvshows|genres|masterprofile|artists)
1st Alternative
albums
albums
matches the characters albums literally (case sensitive)
2nd Alternative
tvshows
tvshows
matches the characters tvshows literally (case sensitive)
3rd Alternative
genres
genres
matches the characters genres literally (case sensitive)
4th Alternative
masterprofile
masterprofile
matches the characters masterprofile literally (case sensitive)
5th Alternative
artists
artists
matches the characters artists literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
Non-capturing group
(?:titles\/)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
titles
matches the characters titles literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
Named Capture Group Identifier
(?<Identifier>[\w\d\-.]+)
Match a single character present in the list below
[\w\d\-.]
+ 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_])
\d matches a digit (equivalent to [0-9])
\- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
. matches the character . with index 4610 (2E16 or 568) 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)
Named Capture Group Season
(?<Season>\d+)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\d
matches a digit (equivalent to [0-9])
+ matches the previous token between one and unlimited 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