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
"
([A-PR-UWYZ](?:[A-HK-Y][0-9](?:[0-9]|[ABEHMNPRV-Y])?|[0-9]([0-9]|[A-HJKPSTUW])?)) ?([0-9][ABD-HJLNP-UW-Z]{2})
"
gi
1st Capturing Group
([A-PR-UWYZ](?:[A-HK-Y][0-9](?:[0-9]|[ABEHMNPRV-Y])?|[0-9]([0-9]|[A-HJKPSTUW])?))
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 insensitive)
R-U matches a single character in the range between R (index 82) and U (index 85) (case insensitive)
WYZ
matches a single character in the list WYZ (case insensitive)
Non-capturing group
(?:[A-HK-Y][0-9](?:[0-9]|[ABEHMNPRV-Y])?|[0-9]([0-9]|[A-HJKPSTUW])?)
1st Alternative
[A-HK-Y][0-9](?:[0-9]|[ABEHMNPRV-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 insensitive)
K-Y matches a single character in the range between K (index 75) and Y (index 89) (case insensitive)
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 insensitive)
Non-capturing group
(?:[0-9]|[ABEHMNPRV-Y])?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
[0-9]
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 insensitive)
2nd Alternative
[ABEHMNPRV-Y]
Match a single character present in the list below
[ABEHMNPRV-Y]
ABEHMNPR
matches a single character in the list ABEHMNPR (case insensitive)
V-Y matches a single character in the range between V (index 86) and Y (index 89) (case insensitive)
2nd Alternative
[0-9]([0-9]|[A-HJKPSTUW])?
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 insensitive)
2nd Capturing Group
([0-9]|[A-HJKPSTUW])?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative
[0-9]
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 insensitive)
2nd Alternative
[A-HJKPSTUW]
Match a single character present in the list below
[A-HJKPSTUW]
A-H matches a single character in the range between A (index 65) and H (index 72) (case insensitive)
JKPSTUW
matches a single character in the list JKPSTUW (case insensitive)
matches the character with index 3210 (2016 or 408) literally (case insensitive)
3rd Capturing Group
([0-9][ABD-HJLNP-UW-Z]{2})
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 insensitive)
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 insensitive)
D-H matches a single character in the range between D (index 68) and H (index 72) (case insensitive)
JLN
matches a single character in the list JLN (case insensitive)
P-U matches a single character in the range between P (index 80) and U (index 85) (case insensitive)
W-Z matches a single character in the range between W (index 87) and Z (index 90) (case insensitive)
Global pattern flags
g modifier: global. All matches (don't return after first match)
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
gi

Test String

Code Generator

Generated Code

Loading code sample...
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report.
For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html