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
/
^(32[^15]|33[^20]|34[0-9]|35[^2-46-9]|36[^45790]|37[^6]|38[^125-7]|39[^4-689])(\d){5,7}
/
g
^ asserts position at start of the string
1st Capturing Group
(32[^15]|33[^20]|34[0-9]|35[^2-46-9]|36[^45790]|37[^6]|38[^125-7]|39[^4-689])
1st Alternative
32[^15]
32
matches the characters 32 literally (case sensitive)
Match a single character not present in the list below
[^15]
15
matches a single character in the list 15 (case sensitive)
2nd Alternative
33[^20]
33
matches the characters 33 literally (case sensitive)
Match a single character not present in the list below
[^20]
20
matches a single character in the list 20 (case sensitive)
3rd Alternative
34[0-9]
34
matches the characters 34 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)
4th Alternative
35[^2-46-9]
35
matches the characters 35 literally (case sensitive)
Match a single character not present in the list below
[^2-46-9]
2-4 matches a single character in the range between 2 (index 50) and 4 (index 52) (case sensitive)
6-9 matches a single character in the range between 6 (index 54) and 9 (index 57) (case sensitive)
5th Alternative
36[^45790]
36
matches the characters 36 literally (case sensitive)
Match a single character not present in the list below
[^45790]
45790
matches a single character in the list 45790 (case sensitive)
6th Alternative
37[^6]
37
matches the characters 37 literally (case sensitive)
Match a single character not present in the list below
[^6]
6 matches the character 6 with index 5410 (3616 or 668) literally (case sensitive)
7th Alternative
38[^125-7]
38
matches the characters 38 literally (case sensitive)
Match a single character not present in the list below
[^125-7]
12
matches a single character in the list 12 (case sensitive)
5-7 matches a single character in the range between 5 (index 53) and 7 (index 55) (case sensitive)
8th Alternative
39[^4-689]
39
matches the characters 39 literally (case sensitive)
Match a single character not present in the list below
[^4-689]
4-6 matches a single character in the range between 4 (index 52) and 6 (index 54) (case sensitive)
89
matches a single character in the list 89 (case sensitive)
2nd Capturing Group
(\d){5,7}
{5,7} matches the previous token between 5 and 7 times, as many times as possible, giving back as needed (greedy)
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
\d matches a digit (equivalent to [0-9])
Global pattern flags
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/
g

Test String