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
/
^(?=[^A-Z\s]*[A-Z])(?=[^a-z\s]*[a-z])(?=[^\d\s]*\d)(?=\w*[\W_])\S{8,}$
/
gm
^ asserts position at start of a line
Positive Lookahead
(?=[^A-Z\s]*[A-Z])
Assert that the Regex below matches
Match a single character not present in the list below
[^A-Z\s]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
Match a single character present in the list below
[A-Z]
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
Positive Lookahead
(?=[^a-z\s]*[a-z])
Assert that the Regex below matches
Match a single character not present in the list below
[^a-z\s]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
Match a single character present in the list below
[a-z]
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
Positive Lookahead
(?=[^\d\s]*\d)
Assert that the Regex below matches
Match a single character not present in the list below
[^\d\s]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
\d matches a digit (equivalent to [0-9])
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
\d matches a digit (equivalent to [0-9])
Positive Lookahead
(?=\w*[\W_])
Assert that the Regex below matches
\w
matches any word character (equivalent to [a-zA-Z0-9_])
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[\W_]
\W matches any non-word character (equivalent to [^a-zA-Z0-9_])
_ matches the character _ with index 9510 (5F16 or 1378) literally (case sensitive)
\S
matches any non-whitespace character (equivalent to [^\r\n\t\f\v ])
{8,} matches the previous token between 8 and unlimited times, as many times as possible, giving back as needed (greedy)
$ asserts position at the end of a line
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