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]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$
/
g
^ asserts position at start of the string
1st Capturing Group
(((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))|((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))|((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))|(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))
1st Alternative
((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))
2nd Capturing Group
((0[1-9]|[12]\d|3[01])\/(0[13578]|1[02])\/((19|[2-9]\d)\d{2}))
3rd Capturing Group
(0[1-9]|[12]\d|3[01])
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
[12]\d
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])
3rd Alternative
3[01]
3 matches the character 3 with index 5110 (3316 or 638) literally (case sensitive)
Match a single character present in the list below
[01]
01
matches a single character in the list 01 (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
4th Capturing Group
(0[13578]|1[02])
1st Alternative
0[13578]
0 matches the character 0 with index 4810 (3016 or 608) 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 character 1 with index 4910 (3116 or 618) 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 4710 (2F16 or 578) literally (case sensitive)
5th Capturing Group
((19|[2-9]\d)\d{2})
6th Capturing Group
(19|[2-9]\d)
1st Alternative
19
19
matches the characters 19 literally (case sensitive)
2nd Alternative
[2-9]\d
Match a single character present in the list below
[2-9]
2-9 matches a single character in the range between 2 (index 50) and 9 (index 57) (case sensitive)
\d matches a digit (equivalent to [0-9])
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
2nd Alternative
((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))
7th Capturing Group
((0[1-9]|[12]\d|30)\/(0[13456789]|1[012])\/((19|[2-9]\d)\d{2}))
8th Capturing Group
(0[1-9]|[12]\d|30)
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
[12]\d
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])
3rd Alternative
30
30
matches the characters 30 literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
9th Capturing Group
(0[13456789]|1[012])
1st Alternative
0[13456789]
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
Match a single character present in the list below
[13456789]
13456789
matches a single character in the list 13456789 (case sensitive)
2nd Alternative
1[012]
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
Match a single character present in the list below
[012]
012
matches a single character in the list 012 (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
10th Capturing Group
((19|[2-9]\d)\d{2})
11th Capturing Group
(19|[2-9]\d)
1st Alternative
19
19
matches the characters 19 literally (case sensitive)
2nd Alternative
[2-9]\d
Match a single character present in the list below
[2-9]
2-9 matches a single character in the range between 2 (index 50) and 9 (index 57) (case sensitive)
\d matches a digit (equivalent to [0-9])
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
3rd Alternative
((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))
12th Capturing Group
((0[1-9]|1\d|2[0-8])\/02\/((19|[2-9]\d)\d{2}))
13th Capturing Group
(0[1-9]|1\d|2[0-8])
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)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
02
matches the characters 02 literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
14th Capturing Group
((19|[2-9]\d)\d{2})
15th Capturing Group
(19|[2-9]\d)
1st Alternative
19
19
matches the characters 19 literally (case sensitive)
2nd Alternative
[2-9]\d
Match a single character present in the list below
[2-9]
2-9 matches a single character in the range between 2 (index 50) and 9 (index 57) (case sensitive)
\d matches a digit (equivalent to [0-9])
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
4th Alternative
(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))
16th Capturing Group
(29\/02\/((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))
29
matches the characters 29 literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
02
matches the characters 02 literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
17th Capturing Group
((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))
1st Alternative
(1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])
18th Capturing Group
(1[6-9]|[2-9]\d)
1st Alternative
1[6-9]
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
Match a single character present in the list below
[6-9]
6-9 matches a single character in the range between 6 (index 54) and 9 (index 57) (case sensitive)
2nd Alternative
[2-9]\d
Match a single character present in the list below
[2-9]
2-9 matches a single character in the range between 2 (index 50) and 9 (index 57) (case sensitive)
\d matches a digit (equivalent to [0-9])
19th Capturing Group
(0[48]|[2468][048]|[13579][26])
1st Alternative
0[48]
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
Match a single character present in the list below
[48]
48
matches a single character in the list 48 (case sensitive)
2nd Alternative
[2468][048]
Match a single character present in the list below
[2468]
2468
matches a single character in the list 2468 (case sensitive)
Match a single character present in the list below
[048]
048
matches a single character in the list 048 (case sensitive)
3rd 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)
2nd Alternative
((16|[2468][048]|[3579][26])00)
20th Capturing Group
((16|[2468][048]|[3579][26])00)
21st Capturing Group
(16|[2468][048]|[3579][26])
1st Alternative
16
16
matches the characters 16 literally (case sensitive)
2nd Alternative
[2468][048]
Match a single character present in the list below
[2468]
2468
matches a single character in the list 2468 (case sensitive)
Match a single character present in the list below
[048]
048
matches a single character in the list 048 (case sensitive)
3rd Alternative
[3579][26]
Match a single character present in the list below
[3579]
3579
matches a single character in the list 3579 (case sensitive)
Match a single character present in the list below
[26]
26
matches a single character in the list 26 (case sensitive)
00
matches the characters 00 literally (case sensitive)
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
Global pattern flags
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
g

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php