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
/
9\/(\w{2,3}){3}\(N\)\d{5,}
/
gm
9 matches the character 9 with index 5710 (3916 or 718) literally (case sensitive)
\/ matches the character / with index 4710 (2F16 or 578) literally (case sensitive)
1st Capturing Group
(\w{2,3}){3}
{3} matches the previous token exactly 3 times
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data
\w
matches any word character (equivalent to [a-zA-Z0-9_])
{2,3} matches the previous token between 2 and 3 times, as many times as possible, giving back as needed (greedy)
\( matches the character ( with index 4010 (2816 or 508) literally (case sensitive)
N matches the character N with index 7810 (4E16 or 1168) literally (case sensitive)
\) matches the character ) with index 4110 (2916 or 518) literally (case sensitive)
\d
matches a digit (equivalent to [0-9])
{5,} matches the previous token between 5 and unlimited times, as many times as possible, giving back as needed (greedy)
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.Try launching the debugger to find out why.

Regular Expression
No Match

/
/
gm

Test String