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
/
^(009665|9665|\+9665|05|5)(5|0|3|6|4|9|1|8|7)([0-9]{7})$
/
^ asserts position at start of the string
1st Capturing Group
(009665|9665|\+9665|05|5)
1st Alternative
009665
009665
matches the characters 009665 literally (case sensitive)
2nd Alternative
9665
9665
matches the characters 9665 literally (case sensitive)
3rd Alternative
\+9665
\+ matches the character + with index 4310 (2B16 or 538) literally (case sensitive)
9665
matches the characters 9665 literally (case sensitive)
4th Alternative
05
05
matches the characters 05 literally (case sensitive)
5th Alternative
5
5 matches the character 5 with index 5310 (3516 or 658) literally (case sensitive)
2nd Capturing Group
(5|0|3|6|4|9|1|8|7)
1st Alternative
5
5 matches the character 5 with index 5310 (3516 or 658) literally (case sensitive)
2nd Alternative
0
0 matches the character 0 with index 4810 (3016 or 608) literally (case sensitive)
3rd Alternative
3
3 matches the character 3 with index 5110 (3316 or 638) literally (case sensitive)
4th Alternative
6
6 matches the character 6 with index 5410 (3616 or 668) literally (case sensitive)
5th Alternative
4
4 matches the character 4 with index 5210 (3416 or 648) literally (case sensitive)
6th Alternative
9
9 matches the character 9 with index 5710 (3916 or 718) literally (case sensitive)
7th Alternative
1
1 matches the character 1 with index 4910 (3116 or 618) literally (case sensitive)
8th Alternative
8
8 matches the character 8 with index 5610 (3816 or 708) literally (case sensitive)
9th Alternative
7
7 matches the character 7 with index 5510 (3716 or 678) literally (case sensitive)
3rd Capturing Group
([0-9]{7})
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 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.Try launching the debugger to find out why.

Regular Expression
No Match

/
/

Test String