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 (4)
"
(?P<dialect>[^+:]+) (?: \+ (?P<driver>[^:]+) )? :// (?P<username>[^:@]+) (?: : (?P<password>[^@]+) )? @ (?P<host>[^:/]+) (?: : (?P<port>\S+) )? / (?P<database>.*)
"
x
Named Capture Group dialect
(?P<dialect>[^+:]+)
Match a single character not present in the list below
[^+:]
+ 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)
Non-capturing group
(?: \+ (?P<driver>[^:]+) )?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\+ matches the character + with index 4310 (2B16 or 538) literally (case sensitive)
Named Capture Group driver
(?P<driver>[^:]+)
Match a single character not present in the list below
[^:]
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
://
matches the characters :// literally (case sensitive)
Named Capture Group username
(?P<username>[^:@]+)
Match a single character not present in the list below
[^:@]
+ 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)
Non-capturing group
(?: : (?P<password>[^@]+) )?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
:
matches the character : with index 1010 (A16 or 128) literally (case sensitive)
Named Capture Group password
(?P<password>[^@]+)
Match a single character not present in the list below
[^@]
+ matches the previous token between one 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)
@
matches the character @ with index 1010 (A16 or 128) literally (case sensitive)
Named Capture Group host
(?P<host>[^:/]+)
Match a single character not present in the list below
[^:/]
+ 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)
Non-capturing group
(?: : (?P<port>\S+) )?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
:
matches the character : with index 1010 (A16 or 128) literally (case sensitive)
Named Capture Group port
(?P<port>\S+)
\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 1010 (A16 or 128) literally (case sensitive)
Named Capture Group database
(?P<database>.*)
.
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
x modifier: extended. Spaces and text after a # in the pattern are ignored
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
x

Test String