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
"
^([a-zA-Z0-9].+?)(\s+)((?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29))(\s+)((0?9|1[0-9]|2[01]):00~(1[0-9]|2[0-2]):00)(\s+)([A-D])(\sC)
"
^ asserts position at start of the string
1st Capturing Group
([a-zA-Z0-9].+?)
Match a single character present in the list below
[a-zA-Z0-9]
a-z matches a single character in the range between a (index 97) and z (index 122) (case sensitive)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
.
matches any character (except for line terminators)
+? matches the previous token between one and unlimited times, as few times as possible, expanding as needed (lazy)
2nd Capturing Group
(\s+)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
3rd Capturing Group
((?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29))
Non-capturing group
(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)
1st Alternative
(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)
Negative Lookahead
(?!0000)
Assert that the Regex below does not match
0000
matches the characters 0000 literally (case sensitive)
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)
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
Non-capturing group
(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)
1st Alternative
(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])
Non-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)
Non-capturing group
(?:0[1-9]|1[0-9]|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[0-9]
1 matches the character 1 with index 4910 (3116 or 618) 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)
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
(?:0[13-9]|1[0-2])-(?:29|30)
Non-capturing group
(?:0[13-9]|1[0-2])
1st Alternative
0[13-9]
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
Match a single character present in the list below
[13-9]
1 matches the character 1 with index 4910 (3116 or 618) literally (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)
- matches the character - with index 4510 (2D16 or 558) literally (case sensitive)
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)
3rd Alternative
(?:0[13578]|1[02])-31
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)
-31
matches the characters -31 literally (case sensitive)
2nd Alternative
(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29
Non-capturing group
(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)
1st Alternative
[0-9]{2}(?:0[48]|[2468][048]|[13579][26])
Match a single character present in the list below
[0-9]
{2} matches the previous token exactly 2 times
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
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
(?:0[48]|[2468][048]|[13579][26])00
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)
00
matches the characters 00 literally (case sensitive)
-02-29
matches the characters -02-29 literally (case sensitive)
4th Capturing Group
(\s+)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
5th Capturing Group
((0?9|1[0-9]|2[01]):00~(1[0-9]|2[0-2]):00)
6th Capturing Group
(0?9|1[0-9]|2[01])
1st Alternative
0?9
0
matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
9 matches the character 9 with index 5710 (3916 or 718) literally (case sensitive)
2nd Alternative
1[0-9]
1 matches the character 1 with index 4910 (3116 or 618) 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)
3rd Alternative
2[01]
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
Match a single character present in the list below
[01]
01
matches a single character in the list 01 (case sensitive)
:00~
matches the characters :00~ literally (case sensitive)
7th Capturing Group
(1[0-9]|2[0-2])
1st Alternative
1[0-9]
1 matches the character 1 with index 4910 (3116 or 618) 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
2[0-2]
2 matches the character 2 with index 5010 (3216 or 628) 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)
:00
matches the characters :00 literally (case sensitive)
8th Capturing Group
(\s+)
\s
matches any whitespace character (equivalent to [\r\n\t\f\v ])
+ matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
9th Capturing Group
([A-D])
Match a single character present in the list below
[A-D]
A-D matches a single character in the range between A (index 65) and D (index 68) (case sensitive)
10th Capturing Group
(\sC)
\s matches any whitespace character (equivalent to [\r\n\t\f\v ])
C matches the character C with index 6710 (4316 or 1038) literally (case sensitive)
Your regular expression does not match the subject string.

Regular Expression
No Match

"
"

Test String

Substitution

Processing...

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html