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
"
([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领WVZHKE]{1}[A-Z]{1}(([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领WVZHKE]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1})
"
gm
1st Alternative
([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领WVZHKE]{1}[A-Z]{1}(([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))
1st Capturing Group
([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领WVZHKE]{1}[A-Z]{1}(([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))
Match a single character present in the list below
[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领WVZHKE]
{1} matches the previous token exactly one time (meaningless quantifier)
京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领WVZHKE
matches a single character in the list 京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领WVZHKE (case sensitive)
Match a single character present in the list below
[A-Z]
{1} matches the previous token exactly one time (meaningless quantifier)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
2nd Capturing Group
(([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4}))
1st Alternative
([0-9]{5}[DF])
3rd Capturing Group
([0-9]{5}[DF])
Match a single character present in the list below
[0-9]
{5} matches the previous token exactly 5 times
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
[DF]
DF
matches a single character in the list DF (case sensitive)
2nd Alternative
([DF]([A-HJ-NP-Z0-9])[0-9]{4})
4th Capturing Group
([DF]([A-HJ-NP-Z0-9])[0-9]{4})
Match a single character present in the list below
[DF]
DF
matches a single character in the list DF (case sensitive)
5th Capturing Group
([A-HJ-NP-Z0-9])
Match a single character present in the list below
[A-HJ-NP-Z0-9]
A-H matches a single character in the range between A (index 65) and H (index 72) (case sensitive)
J-N matches a single character in the range between J (index 74) and N (index 78) (case sensitive)
P-Z matches a single character in the range between P (index 80) and Z (index 90) (case sensitive)
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
[0-9]
{4} matches the previous token exactly 4 times
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
2nd Alternative
([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领WVZHKE]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1})
6th Capturing Group
([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领WVZHKE]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1})
Match a single character present in the list below
[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领WVZHKE]
{1} matches the previous token exactly one time (meaningless quantifier)
京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领WVZHKE
matches a single character in the list 京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领WVZHKE (case sensitive)
Match a single character present in the list below
[A-Z]
{1} matches the previous token exactly one time (meaningless quantifier)
A-Z matches a single character in the range between A (index 65) and Z (index 90) (case sensitive)
Match a single character present in the list below
[A-HJ-NP-Z0-9]
{4} matches the previous token exactly 4 times
A-H matches a single character in the range between A (index 65) and H (index 72) (case sensitive)
J-N matches a single character in the range between J (index 74) and N (index 78) (case sensitive)
P-Z matches a single character in the range between P (index 80) and Z (index 90) (case sensitive)
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-HJ-NP-Z0-9挂学警港澳]
{1} matches the previous token exactly one time (meaningless quantifier)
A-H matches a single character in the range between A (index 65) and H (index 72) (case sensitive)
J-N matches a single character in the range between J (index 74) and N (index 78) (case sensitive)
P-Z matches a single character in the range between P (index 80) and Z (index 90) (case sensitive)
0-9 matches a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)
挂学警港澳
matches a single character in the list 挂学警港澳 (case sensitive)
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