Regular Expressions 101

@regex101
Donate
Sponsor
Contact
Bug Reports & Feedback
Wiki
Whats new?

Save & Share

  • Save Regex
    ctrl+s
  • Update Regex
    ctrl+⇧+s

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python 2.7
  • Golang (RE2)

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
^(\+{0,})(\d{0,})([(]{1}\d{1,3}[)]{0,}){0,}(\s?\d+|\+\d{2,3}\s{1}\d+|\d+){1}[\s|-]?\d+([\s|-]?\d+){1,2}(\s){0,}$
/
gm
^ asserts position at start of a line
1st Capturing Group
(\+{0,})
\+{0,}
matches the character + literally (case sensitive)
{0,} Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
2nd Capturing Group
(\d{0,})
\d{0,}
matches a digit (equal to [0-9])
{0,} Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
3rd Capturing Group
([(]{1}\d{1,3}[)]{0,}){0,}
{0,} Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
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
Match a single character present in the list below
[(]{1}
{1} Quantifier — Matches exactly one time (meaningless quantifier)
( matches the character ( literally (case sensitive)
\d{1,3}
matches a digit (equal to [0-9])
{1,3} Quantifier — Matches between 1 and 3 times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[)]{0,}
{0,} Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
) matches the character ) literally (case sensitive)
4th Capturing Group
(\s?\d+|\+\d{2,3}\s{1}\d+|\d+){1}
{1} Quantifier — Matches exactly one time (meaningless quantifier)
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
1st Alternative
\s?\d+
\s?
matches any whitespace character (equal to [\r\n\t\f\v ])
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
\d+
matches a digit (equal to [0-9])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
2nd Alternative
\+\d{2,3}\s{1}\d+
\+ matches the character + literally (case sensitive)
\d{2,3}
matches a digit (equal to [0-9])
\s{1}
matches any whitespace character (equal to [\r\n\t\f\v ])
\d+
matches a digit (equal to [0-9])
3rd Alternative
\d+
\d+
matches a digit (equal to [0-9])
Match a single character present in the list below
[\s|-]?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
\s matches any whitespace character (equal to [\r\n\t\f\v ])
|- matches a single character in the list |- (case sensitive)
\d+
matches a digit (equal to [0-9])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
5th Capturing Group
([\s|-]?\d+){1,2}
{1,2} Quantifier — Matches between 1 and 2 times, as many times as possible, giving back as needed (greedy)
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
Match a single character present in the list below
[\s|-]?
\d+
matches a digit (equal to [0-9])
6th Capturing Group
(\s){0,}
{0,} Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)
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
\s matches any whitespace character (equal to [\r\n\t\f\v ])
$ asserts position at the end of a line
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