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 (7)
/
(X(-|\.)?0?\d{7}(-|\.)?[A-Z]|[A-Z](-|\.)?\d{7}(-|\.)?[0-9A-Z]|\d{8}(-|\.)?[A-Z])$
/
gmi
1st Capturing Group
(X(-|\.)?0?\d{7}(-|\.)?[A-Z]|[A-Z](-|\.)?\d{7}(-|\.)?[0-9A-Z]|\d{8}(-|\.)?[A-Z])
1st Alternative
X(-|\.)?0?\d{7}(-|\.)?[A-Z]
X matches the character X with index 8810 (5816 or 1308) literally (case insensitive)
2nd Capturing Group
(-|\.)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
-
- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
2nd Alternative
\.
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
0
matches the character 0 with index 4810 (3016 or 608) literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
{7} matches the previous token exactly 7 times
3rd Capturing Group
(-|\.)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
-
- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
2nd Alternative
\.
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
Match a single character present in the list below
[A-Z]
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case insensitive)
2nd Alternative
[A-Z](-|\.)?\d{7}(-|\.)?[0-9A-Z]
Match a single character present in the list below
[A-Z]
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case insensitive)
4th Capturing Group
(-|\.)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
-
- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
2nd Alternative
\.
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
\d
matches a digit (equivalent to [0-9])
{7} matches the previous token exactly 7 times
5th Capturing Group
(-|\.)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
-
- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
2nd Alternative
\.
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
Match a single character present in the list below
[0-9A-Z]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case insensitive)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case insensitive)
3rd Alternative
\d{8}(-|\.)?[A-Z]
\d
matches a digit (equivalent to [0-9])
{8} matches the previous token exactly 8 times
6th Capturing Group
(-|\.)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
-
- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
2nd Alternative
\.
\. matches the character . with index 4610 (2E16 or 568) literally (case insensitive)
Match a single character present in the list below
[A-Z]
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case insensitive)
$ 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)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])

Regular Expression

/
/
gmi

Unit Tests

Unspecified unit test
Unspecified unit test
Unspecified unit test
Unspecified unit test
Unspecified unit test
Unspecified unit test
Unspecified unit test