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-9]{4}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))((([0-1][0-9])|(2[0-3]))[0-5][0-9][0-5][0-9](\.[0-9]{3}((\[[\+\-]?(0[0-9]|1[0-4])(:(00|30|45))?\])?)?)?)?)$
"
^ asserts position at start of the string
1st Capturing Group
([0-9]{4}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))((([0-1][0-9])|(2[0-3]))[0-5][0-9][0-5][0-9](\.[0-9]{3}((\[[\+\-]?(0[0-9]|1[0-4])(:(00|30|45))?\])?)?)?)?)
Match a single character present in the list below
[0-9]
{4} matches the previous token exactly 4 times
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
2nd Capturing Group
((0[1-9])|(1[0-2]))
1st Alternative
(0[1-9])
3rd 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])
4th 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)
5th Capturing Group
((0[1-9])|([1-2][0-9])|(3[0-1]))
1st Alternative
(0[1-9])
6th 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-2][0-9])
7th Capturing Group
([1-2][0-9])
Match a single character present in the list below
[1-2]
1-2 matches a single character in the range between 1 (index 49) and 2 (index 50) (case sensitive)
Match a single character present in the list below
[0-9]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
3rd Alternative
(3[0-1])
8th Capturing Group
(3[0-1])
3 matches the character 3 with index 5110 (3316 or 638) literally (case sensitive)
Match a single character present in the list below
[0-1]
0-1 matches a single character in the range between 0 (index 48) and 1 (index 49) (case sensitive)
9th Capturing Group
((([0-1][0-9])|(2[0-3]))[0-5][0-9][0-5][0-9](\.[0-9]{3}((\[[\+\-]?(0[0-9]|1[0-4])(:(00|30|45))?\])?)?)?)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
10th Capturing Group
(([0-1][0-9])|(2[0-3]))
1st Alternative
([0-1][0-9])
11th Capturing Group
([0-1][0-9])
Match a single character present in the list below
[0-1]
0-1 matches a single character in the range between 0 (index 48) and 1 (index 49) (case sensitive)
Match a single character present in the list below
[0-9]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
2nd Alternative
(2[0-3])
12th Capturing Group
(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)
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)
Match a single character present in the list below
[0-9]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
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)
Match a single character present in the list below
[0-9]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
13th Capturing Group
(\.[0-9]{3}((\[[\+\-]?(0[0-9]|1[0-4])(:(00|30|45))?\])?)?)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
Match a single character present in the list below
[0-9]
{3} matches the previous token exactly 3 times
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
14th Capturing Group
((\[[\+\-]?(0[0-9]|1[0-4])(:(00|30|45))?\])?)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
15th Capturing Group
(\[[\+\-]?(0[0-9]|1[0-4])(:(00|30|45))?\])?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\[ matches the character [ with index 9110 (5B16 or 1338) literally (case sensitive)
Match a single character present in the list below
[\+\-]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\+ matches the character + with index 4310 (2B16 or 538) literally (case sensitive)
\- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
16th Capturing Group
(0[0-9]|1[0-4])
1st Alternative
0[0-9]
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
Match a single character present in the list below
[0-9]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
2nd Alternative
1[0-4]
17th Capturing Group
(:(00|30|45))?
\] matches the character ] with index 9310 (5D16 or 1358) 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)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"

Test String