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
"
(?P<schema>.*://)?(?P<cedentials>.*@)?(?P<www>www\.)?(?P<domain>[\w\.]+)(?P<path_query>/?.*)?
"
g
Named Capture Group schema
(?P<schema>.*://)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
://
matches the characters :// literally (case sensitive)
Named Capture Group cedentials
(?P<cedentials>.*@)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
.
matches any character (except for line terminators)
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
@ matches the character @ with index 6410 (4016 or 1008) literally (case sensitive)
Named Capture Group www
(?P<www>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)
Named Capture Group domain
(?P<domain>[\w\.]+)
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 4610 (2E16 or 568) literally (case sensitive)
Named Capture Group path_query
(?P<path_query>/?.*)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
/
matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
.
matches any character (except for line terminators)
* matches the previous token between zero 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)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
g

Test String