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
/
^(0[1-9]|1\d|2[0-8]|29(?=-\d\d-(?!1[01345789]00|2[1235679]00)\d\d(?:[02468][048]|[13579][26]))|30(?!-02)|31(?=-0[13578]|-1[02]))-(0[1-9]|1[0-2])-([12]\d{3}) ([01]\d|2[0-3]):([0-5]\d):([0-5]\d)$
/
^ asserts position at start of the string
1st Capturing Group
(0[1-9]|1\d|2[0-8]|29(?=-\d\d-(?!1[01345789]00|2[1235679]00)\d\d(?:[02468][048]|[13579][26]))|30(?!-02)|31(?=-0[13578]|-1[02]))
1st Alternative
0[1-9]
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
Match a single character present in the list below
[1-9]
1-9 matches a single character in the range between 1 (index 49) and 9 (index 57) (case sensitive)
2nd Alternative
1\d
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
3rd Alternative
2[0-8]
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
Match a single character present in the list below
[0-8]
0-8 matches a single character in the range between 0 (index 48) and 8 (index 56) (case sensitive)
4th Alternative
29(?=-\d\d-(?!1[01345789]00|2[1235679]00)\d\d(?:[02468][048]|[13579][26]))
29
matches the characters 29 literally (case sensitive)
Positive Lookahead
(?=-\d\d-(?!1[01345789]00|2[1235679]00)\d\d(?:[02468][048]|[13579][26]))
Assert that the Regex below matches
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
Negative Lookahead
(?!1[01345789]00|2[1235679]00)
Assert that the Regex below does not match
1st Alternative
1[01345789]00
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
Match a single character present in the list below
[01345789]
01345789
matches a single character in the list 01345789 (case sensitive)
00
matches the characters 00 literally (case sensitive)
2nd Alternative
2[1235679]00
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
Match a single character present in the list below
[1235679]
1235679
matches a single character in the list 1235679 (case sensitive)
00
matches the characters 00 literally (case sensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
Non-capturing group
(?:[02468][048]|[13579][26])
1st Alternative
[02468][048]
Match a single character present in the list below
[02468]
02468
matches a single character in the list 02468 (case sensitive)
Match a single character present in the list below
[048]
048
matches a single character in the list 048 (case sensitive)
2nd Alternative
[13579][26]
Match a single character present in the list below
[13579]
13579
matches a single character in the list 13579 (case sensitive)
Match a single character present in the list below
[26]
26
matches a single character in the list 26 (case sensitive)
5th Alternative
30(?!-02)
30
matches the characters 30 literally (case sensitive)
Negative Lookahead
(?!-02)
Assert that the Regex below does not match
-02
matches the characters -02 literally (case sensitive)
6th Alternative
31(?=-0[13578]|-1[02])
31
matches the characters 31 literally (case sensitive)
Positive Lookahead
(?=-0[13578]|-1[02])
Assert that the Regex below matches
1st Alternative
-0[13578]
-0
matches the characters -0 literally (case sensitive)
Match a single character present in the list below
[13578]
13578
matches a single character in the list 13578 (case sensitive)
2nd Alternative
-1[02]
-1
matches the characters -1 literally (case sensitive)
Match a single character present in the list below
[02]
02
matches a single character in the list 02 (case sensitive)
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
2nd Capturing Group
(0[1-9]|1[0-2])
1st Alternative
0[1-9]
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
Match a single character present in the list below
[1-9]
1-9 matches a single character in the range between 1 (index 49) and 9 (index 57) (case sensitive)
2nd Alternative
1[0-2]
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
Match a single character present in the list below
[0-2]
0-2 matches a single character in the range between 0 (index 48) and 2 (index 50) (case sensitive)
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
3rd Capturing Group
([12]\d{3})
Match a single character present in the list below
[12]
12
matches a single character in the list 12 (case sensitive)
\d
matches a digit (equivalent to [0-9])
{3} matches the previous token exactly 3 times
matches the character with index 3210 (2016 or 408) literally (case sensitive)
4th Capturing Group
([01]\d|2[0-3])
1st Alternative
[01]\d
Match a single character present in the list below
[01]
01
matches a single character in the list 01 (case sensitive)
\d matches a digit (equivalent to [0-9])
2nd Alternative
2[0-3]
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
Match a single character present in the list below
[0-3]
0-3 matches a single character in the range between 0 (index 48) and 3 (index 51) (case sensitive)
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
5th Capturing Group
([0-5]\d)
Match a single character present in the list below
[0-5]
0-5 matches a single character in the range between 0 (index 48) and 5 (index 53) (case sensitive)
\d matches a digit (equivalent to [0-9])
: matches the character : with index 5810 (3A16 or 728) literally (case sensitive)
6th Capturing Group
([0-5]\d)
Match a single character present in the list below
[0-5]
0-5 matches a single character in the range between 0 (index 48) and 5 (index 53) (case sensitive)
\d matches a digit (equivalent to [0-9])
$ asserts position at the end of the string
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions