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]*((0)1[23456789]|(0|1)2[3456789]|(0|1|2)3[456789]|(0|1|2|3)4[56789]|(0|1|2|3|4)5[6789]|(0|1|2|3|4|5)6[789]|(0|1|2|3|4|5|6)7[89]|(0|1|2|3|4|5|6|7)8(9))[0-9]*$
"
gmx
^ asserts position at start of a line
Match a single character present in the list below
[0-9]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
1st Capturing Group
((0)1[23456789]|(0|1)2[3456789]|(0|1|2)3[456789]|(0|1|2|3)4[56789]|(0|1|2|3|4)5[6789]|(0|1|2|3|4|5)6[789]|(0|1|2|3|4|5|6)7[89]|(0|1|2|3|4|5|6|7)8(9))
1st Alternative
(0)1[23456789]
2nd Capturing Group
(0)
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
Match a single character present in the list below
[23456789]
23456789
matches a single character in the list 23456789 (case sensitive)
2nd Alternative
(0|1)2[3456789]
3rd Capturing Group
(0|1)
1st Alternative
0
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
2nd Alternative
1
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
Match a single character present in the list below
[3456789]
3456789
matches a single character in the list 3456789 (case sensitive)
3rd Alternative
(0|1|2)3[456789]
4th Capturing Group
(0|1|2)
1st Alternative
0
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
2nd Alternative
1
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
3rd Alternative
2
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
3 matches the character 3 with index 5110 (3316 or 638) literally (case sensitive)
Match a single character present in the list below
[456789]
456789
matches a single character in the list 456789 (case sensitive)
4th Alternative
(0|1|2|3)4[56789]
5th Capturing Group
(0|1|2|3)
1st Alternative
0
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
2nd Alternative
1
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
3rd Alternative
2
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
4th Alternative
3
3 matches the character 3 with index 5110 (3316 or 638) literally (case sensitive)
4 matches the character 4 with index 5210 (3416 or 648) literally (case sensitive)
Match a single character present in the list below
[56789]
56789
matches a single character in the list 56789 (case sensitive)
5th Alternative
(0|1|2|3|4)5[6789]
6th Capturing Group
(0|1|2|3|4)
1st Alternative
0
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
2nd Alternative
1
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
3rd Alternative
2
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
4th Alternative
3
3 matches the character 3 with index 5110 (3316 or 638) literally (case sensitive)
5th Alternative
4
4 matches the character 4 with index 5210 (3416 or 648) literally (case sensitive)
5 matches the character 5 with index 5310 (3516 or 658) literally (case sensitive)
Match a single character present in the list below
[6789]
6789
matches a single character in the list 6789 (case sensitive)
6th Alternative
(0|1|2|3|4|5)6[789]
7th Capturing Group
(0|1|2|3|4|5)
1st Alternative
0
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
2nd Alternative
1
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
3rd Alternative
2
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
4th Alternative
3
3 matches the character 3 with index 5110 (3316 or 638) literally (case sensitive)
5th Alternative
4
4 matches the character 4 with index 5210 (3416 or 648) literally (case sensitive)
6th Alternative
5
6 matches the character 6 with index 5410 (3616 or 668) literally (case sensitive)
Match a single character present in the list below
[789]
789
matches a single character in the list 789 (case sensitive)
7th Alternative
(0|1|2|3|4|5|6)7[89]
8th Capturing Group
(0|1|2|3|4|5|6)
1st Alternative
0
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
2nd Alternative
1
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
3rd Alternative
2
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
4th Alternative
3
3 matches the character 3 with index 5110 (3316 or 638) literally (case sensitive)
5th Alternative
4
6th Alternative
5
7th Alternative
6
7 matches the character 7 with index 5510 (3716 or 678) literally (case sensitive)
Match a single character present in the list below
[89]
89
matches a single character in the list 89 (case sensitive)
8th Alternative
(0|1|2|3|4|5|6|7)8(9)
9th Capturing Group
(0|1|2|3|4|5|6|7)
1st Alternative
0
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
2nd Alternative
1
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
3rd Alternative
2
2 matches the character 2 with index 5010 (3216 or 628) literally (case sensitive)
4th Alternative
3
5th Alternative
4
6th Alternative
5
7th Alternative
6
8th Alternative
7
8 matches the character 8 with index 5610 (3816 or 708) literally (case sensitive)
10th Capturing Group
(9)
9 matches the character 9 with index 5710 (3916 or 718) literally (case sensitive)
Match a single character present in the list below
[0-9]
* matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (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)
x modifier: extended. Spaces and text after a # in the pattern are ignored
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
gmx

Test String