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
"
^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2})$
"
^ asserts position at start of the string
1st Capturing Group
(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2})
1st Alternative
GIR ?0AA
GIR
matches the characters GIR literally (case sensitive)
matches the character with index 3210 (2016 or 408) literally (case sensitive)
0AA
matches the characters 0AA literally (case sensitive)
2nd Alternative
[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2}
Match a single character present in the list below
[A-PR-UWYZ]
A-P matches a single character in the range between A (index 65) and P (index 80) (case sensitive)
R-U matches a single character in the range between R (index 82) and U (index 85) (case sensitive)
WYZ
matches a single character in the list WYZ (case sensitive)
2nd Capturing Group
([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW])
1st Alternative
[0-9]{1,2}
Match a single character present in the list below
[0-9]
{1,2} matches the previous token between 1 and 2 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)
2nd Alternative
([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)
3rd Capturing Group
([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)
Match a single character present in the list below
[A-HK-Y]
A-H matches a single character in the range between A (index 65) and H (index 72) (case sensitive)
K-Y matches a single character in the range between K (index 75) and Y (index 89) (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 Capturing Group
([0-9ABEHMNPRV-Y])?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[0-9ABEHMNPRV-Y]
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
ABEHMNPR
matches a single character in the list ABEHMNPR (case sensitive)
V-Y matches a single character in the range between V (index 86) and Y (index 89) (case sensitive)
3rd Alternative
[0-9][A-HJKPS-UW]
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)
Match a single character present in the list below
[A-HJKPS-UW]
A-H matches a single character in the range between A (index 65) and H (index 72) (case sensitive)
JKP
matches a single character in the list JKP (case sensitive)
S-U matches a single character in the range between S (index 83) and U (index 85) (case sensitive)
W matches the character W with index 8710 (5716 or 1278) literally (case sensitive)
matches the character with index 3210 (2016 or 408) 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)
Match a single character present in the list below
[ABD-HJLNP-UW-Z]
{2} matches the previous token exactly 2 times
AB
matches a single character in the list AB (case sensitive)
D-H matches a single character in the range between D (index 68) and H (index 72) (case sensitive)
JLN
matches a single character in the list JLN (case sensitive)
P-U matches a single character in the range between P (index 80) and U (index 85) (case sensitive)
W-Z matches a single character in the range between W (index 87) and Z (index 90) (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.

Regular Expression
No Match

r"
"

Test String