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
"
\b[\d]{2,3}[\.]?[\d]{3}[\.]?[\d]{3}[\/]?[\d]{4}[-]?[\d]{2}\s
"
gi
\b assert position at a word boundary: (^\w|\w$|\W\w|\w\W)
Match a single character present in the list below
[\d]
{2,3} matches the previous token between 2 and 3 times, as many times as possible, giving back as needed (greedy)
\d matches a digit (equivalent to [0-9])
Match a single character present in the list below
[\.]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\. matches the character . with index 4610 (2E16 or 568) literally (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
[\.]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\. matches the character . with index 4610 (2E16 or 568) literally (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
[\/]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\/ matches the character / with index 4710 (2F16 or 578) literally (case insensitive)
Match a single character present in the list below
[\d]
{4} matches the previous token exactly 4 times
\d matches a digit (equivalent to [0-9])
Match a single character present in the list below
[-]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
- matches the character - with index 4510 (2D16 or 558) literally (case insensitive)
Match a single character present in the list below
[\d]
{2} matches the previous token exactly 2 times
\d matches a digit (equivalent to [0-9])
\s matches any whitespace character (equivalent to [\r\n\t\f\v  ])
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