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
"
((([12]{1}\d\d)|(1-9]\d)|([1-9]))[\.]){3}(([12]{1}\d\d)|([1-9]\d)|([1-9]))
"
1st Capturing Group
((([12]{1}\d\d)|(1-9]\d)|([1-9]))[\.]){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
2nd Capturing Group
(([12]{1}\d\d)|(1-9]\d)|([1-9]))
1st Alternative
([12]{1}\d\d)
3rd Capturing Group
([12]{1}\d\d)
Match a single character present in the list below
[12]
{1} matches the previous token exactly one time (meaningless quantifier)
12
matches a single character in the list 12 (case sensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
2nd Alternative
(1-9]\d)
4th Capturing Group
(1-9]\d)
1-9]
matches the characters 1-9] literally (case sensitive)
\d matches a digit (equivalent to [0-9])
3rd Alternative
([1-9])
5th Capturing Group
([1-9])
Match a single character present in the list below
[1-9]
1-9 matches a single character in the range between 1 (index 49) and 9 (index 57) (case sensitive)
Match a single character present in the list below
[\.]
\. matches the character . with index 4610 (2E16 or 568) literally (case sensitive)
6th Capturing Group
(([12]{1}\d\d)|([1-9]\d)|([1-9]))
1st Alternative
([12]{1}\d\d)
7th Capturing Group
([12]{1}\d\d)
Match a single character present in the list below
[12]
{1} matches the previous token exactly one time (meaningless quantifier)
12
matches a single character in the list 12 (case sensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
2nd Alternative
([1-9]\d)
8th Capturing Group
([1-9]\d)
Match a single character present in the list below
[1-9]
1-9 matches a single character in the range between 1 (index 49) and 9 (index 57) (case sensitive)
\d matches a digit (equivalent to [0-9])
3rd Alternative
([1-9])
9th Capturing Group
([1-9])
Match a single character present in the list below
[1-9]
1-9 matches a single character in the range between 1 (index 49) and 9 (index 57) (case sensitive)
Your regular expression does not match the subject string.

Regular Expression
No Match

r"
"

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