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 (6)
"
^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$
"
1st Alternative
^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$
^ asserts position at start of the string
Non-capturing group
(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))
1st Alternative
(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1
Non-capturing group
(?:31(\/|-|\.)(?:0?[13578]|1[02]))
31
matches the characters 31 literally (case sensitive)
1st Capturing Group
(\/|-|\.)
1st Alternative
\/
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
2nd Alternative
-
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
3rd Alternative
\.
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
Non-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)
\1 matches the same text as most recently matched by the 1st capturing group
2nd Alternative
(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2)
Non-capturing group
(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2)
Non-capturing group
(?:29|30)
1st Alternative
29
29
matches the characters 29 literally (case sensitive)
2nd Alternative
30
30
matches the characters 30 literally (case sensitive)
2nd Capturing Group
(\/|-|\.)
1st Alternative
\/
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
2nd Alternative
-
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
3rd Alternative
\.
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
Non-capturing group
(?:0?[1,3-9]|1[0-2])
1st Alternative
0?[1,3-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,3-9]
1,
matches a single character in the list 1, (case sensitive)
3-9 matches a single character in the range between 3 (index 51) 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)
\2 matches the same text as most recently matched by the 2nd capturing group
Non-capturing group
(?:(?:1[6-9]|[2-9]\d)?\d{2})
Non-capturing group
(?:1[6-9]|[2-9]\d)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
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])
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
2nd Alternative
^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$
^ asserts position at start of the string
Non-capturing group
(?:29(\/|-|\.)0?2\3(?:(?:(?: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)
3rd Capturing Group
(\/|-|\.)
1st Alternative
\/
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
2nd Alternative
-
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
3rd Alternative
\.
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
0
matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
\3 matches the same text as most recently matched by the 3rd capturing group
Non-capturing group
(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))
Non-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])
Non-capturing group
(?:1[6-9]|[2-9]\d)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
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])
Non-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)
Non-capturing group
(?:(?:16|[2468][048]|[3579][26])00)
Non-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)
3rd Alternative
^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$
^ asserts position at start of the string
Non-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)
4th Capturing Group
(\/|-|\.)
1st Alternative
\/
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
2nd Alternative
-
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
3rd Alternative
\.
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
Non-capturing group
(?:(?:0?[1-9])|(?:1[0-2]))
1st Alternative
(?:0?[1-9])
Non-capturing group
(?: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])
Non-capturing group
(?: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)
\4 matches the same text as most recently matched by the 4th capturing group
Non-capturing group
(?:(?:1[6-9]|[2-9]\d)?\d{2})
Non-capturing group
(?:1[6-9]|[2-9]\d)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
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])
\d
matches a digit (equivalent to [0-9])
{2} matches the previous token exactly 2 times
$ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"

Test String