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
`
^(((\d{3}[1-9]|\d{2}[1-9]\d|\d[1-9]\d{2}|[1-9]\d{3})(\/)(((0[13578]|1[02])(\/)(0[1-9]|[12]\d|3[01]))|((0[469]|11)(\/)(0[1-9]|[12]\d|30))|(02(\/)(0[1-9]|[1]\d|2[0-8]))))|(((\d{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))(\/)02(\/)29))$
`
gm
^ asserts position at start of a line
1st Capturing Group
(((\d{3}[1-9]|\d{2}[1-9]\d|\d[1-9]\d{2}|[1-9]\d{3})(\/)(((0[13578]|1[02])(\/)(0[1-9]|[12]\d|3[01]))|((0[469]|11)(\/)(0[1-9]|[12]\d|30))|(02(\/)(0[1-9]|[1]\d|2[0-8]))))|(((\d{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))(\/)02(\/)29))
1st Alternative
((\d{3}[1-9]|\d{2}[1-9]\d|\d[1-9]\d{2}|[1-9]\d{3})(\/)(((0[13578]|1[02])(\/)(0[1-9]|[12]\d|3[01]))|((0[469]|11)(\/)(0[1-9]|[12]\d|30))|(02(\/)(0[1-9]|[1]\d|2[0-8]))))
2nd Capturing Group
((\d{3}[1-9]|\d{2}[1-9]\d|\d[1-9]\d{2}|[1-9]\d{3})(\/)(((0[13578]|1[02])(\/)(0[1-9]|[12]\d|3[01]))|((0[469]|11)(\/)(0[1-9]|[12]\d|30))|(02(\/)(0[1-9]|[1]\d|2[0-8]))))
3rd Capturing Group
(\d{3}[1-9]|\d{2}[1-9]\d|\d[1-9]\d{2}|[1-9]\d{3})
1st Alternative
\d{3}[1-9]
\d
matches a digit (equivalent to [0-9])
{3} matches the previous token exactly 3 times
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
\d{2}[1-9]\d
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
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)
\d matches a digit (equivalent to [0-9])
3rd Alternative
\d[1-9]\d{2}
\d matches a digit (equivalent to [0-9])
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)
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
4th Alternative
[1-9]\d{3}
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)
\d
matches a digit (equivalent to [0-9])
{3} matches the previous token exactly 3 times
4th Capturing Group
(\/)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
5th Capturing Group
(((0[13578]|1[02])(\/)(0[1-9]|[12]\d|3[01]))|((0[469]|11)(\/)(0[1-9]|[12]\d|30))|(02(\/)(0[1-9]|[1]\d|2[0-8])))
1st Alternative
((0[13578]|1[02])(\/)(0[1-9]|[12]\d|3[01]))
6th Capturing Group
((0[13578]|1[02])(\/)(0[1-9]|[12]\d|3[01]))
7th 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)
8th Capturing Group
(\/)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
9th 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)
2nd Alternative
((0[469]|11)(\/)(0[1-9]|[12]\d|30))
10th Capturing Group
((0[469]|11)(\/)(0[1-9]|[12]\d|30))
11th Capturing Group
(0[469]|11)
1st Alternative
0[469]
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
Match a single character present in the list below
[469]
469
matches a single character in the list 469 (case sensitive)
2nd Alternative
11
11
matches the characters 11 literally (case sensitive)
12th Capturing Group
(\/)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
13th 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)
3rd Alternative
(02(\/)(0[1-9]|[1]\d|2[0-8]))
14th Capturing Group
(02(\/)(0[1-9]|[1]\d|2[0-8]))
02
matches the characters 02 literally (case sensitive)
15th Capturing Group
(\/)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
16th 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
Match a single character present in the list below
[1]
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)
2nd Alternative
(((\d{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))(\/)02(\/)29)
17th Capturing Group
(((\d{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))(\/)02(\/)29)
18th Capturing Group
((\d{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))
1st Alternative
(\d{2})(0[48]|[2468][048]|[13579][26])
19th Capturing Group
(\d{2})
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
20th 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
((0[48]|[2468][048]|[3579][26])00)
21st Capturing Group
((0[48]|[2468][048]|[3579][26])00)
22nd Capturing Group
(0[48]|[2468][048]|[3579][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
[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)
23rd Capturing Group
(\/)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
02
matches the characters 02 literally (case sensitive)
24th Capturing Group
(\/)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
29
matches the characters 29 literally (case sensitive)
$ 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.

Regular Expression
No Match

`
`
gm

Test String