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
"
(?i)(?:(?P<pre1994>[a-hj-np-z][\d]{1,7})|(?P<from1995to2014>[a-z]{3}[\d]{3})|(?P<from2015>[a-z]{2}[\d]{3}[a-z]{2}))
"
gm
(?i)
match the remainder of the pattern with the following effective flags: gmi
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])
Non-capturing group
(?:(?P<pre1994>[a-hj-np-z][\d]{1,7})|(?P<from1995to2014>[a-z]{3}[\d]{3})|(?P<from2015>[a-z]{2}[\d]{3}[a-z]{2}))
1st Alternative
(?P<pre1994>[a-hj-np-z][\d]{1,7})
Named Capture Group pre1994
(?P<pre1994>[a-hj-np-z][\d]{1,7})
Match a single character present in the list below
[a-hj-np-z]
a-h matches a single character in the range between a (index 97) and h (index 104) (case insensitive)
j-n matches a single character in the range between j (index 106) and n (index 110) (case insensitive)
p-z matches a single character in the range between p (index 112) and z (index 122) (case insensitive)
Match a single character present in the list below
[\d]
{1,7} matches the previous token between 1 and 7 times, as many times as possible, giving back as needed (greedy)
\d matches a digit (equivalent to [0-9])
2nd Alternative
(?P<from1995to2014>[a-z]{3}[\d]{3})
Named Capture Group from1995to2014
(?P<from1995to2014>[a-z]{3}[\d]{3})
Match a single character present in the list below
[a-z]
{3} matches the previous token exactly 3 times
a-z matches a single character in the range between a (index 97) and z (index 122) (case insensitive)
Match a single character present in the list below
[\d]
{3} matches the previous token exactly 3 times
\d matches a digit (equivalent to [0-9])
3rd Alternative
(?P<from2015>[a-z]{2}[\d]{3}[a-z]{2})
Named Capture Group from2015
(?P<from2015>[a-z]{2}[\d]{3}[a-z]{2})
Match a single character present in the list below
[a-z]
{2} matches the previous token exactly 2 times
a-z matches a single character in the range between a (index 97) and z (index 122) (case insensitive)
Match a single character present in the list below
[\d]
{3} matches the previous token exactly 3 times
\d matches a digit (equivalent to [0-9])
Match a single character present in the list below
[a-z]
{2} matches the previous token exactly 2 times
a-z matches a single character in the range between a (index 97) and z (index 122) (case insensitive)
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)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"
gm

Test String