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
/
^(221|00221|\+221)?(77|78|75|70|76)[0-9]{7}$
/
mg
^ asserts position at start of a line
1st Capturing Group
(221|00221|\+221)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
221
221
matches the characters 221 literally (case sensitive)
2nd Alternative
00221
00221
matches the characters 00221 literally (case sensitive)
3rd Alternative
\+221
\+ matches the character + with index 4310 (2B16 or 538) literally (case sensitive)
221
matches the characters 221 literally (case sensitive)
2nd Capturing Group
(77|78|75|70|76)
1st Alternative
77
77
matches the characters 77 literally (case sensitive)
2nd Alternative
78
78
matches the characters 78 literally (case sensitive)
3rd Alternative
75
75
matches the characters 75 literally (case sensitive)
4th Alternative
70
70
matches the characters 70 literally (case sensitive)
5th Alternative
76
76
matches the characters 76 literally (case sensitive)
Match a single character present in the list below
[0-9]
{7} matches the previous token exactly 7 times
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
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
g modifier: global. All matches (don't return after first match)
Your regular expression does not match the subject string.

Regular Expression
No Match

/
/
mg

Test String