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
  • Java 8

Function

  • Match
  • Substitution
  • List
  • Unit Tests
/
^((\+1)?[\s-])?\([2-9]\d\d\)[\s-][2-9]\d\d[\s-]\d\d\d\d
/
gi
^ asserts position at start of the string
1st Capturing Group
((\+1)?[\s-])?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
2nd Capturing Group
(\+1)?
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\+ matches the character + literally (case insensitive)
1 matches the character 1 literally (case insensitive)
Match a single character present in the list below
[\s-]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\s matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
- matches the character - literally (case insensitive)
This hyphen is treated literally, which might be confusing for others. Consider escaping it or placing at the start or end of the class!
\(
matches the character ( literally (case insensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[2-9]
2-9 matches a single character in the range between 2 (index 50) and 9 (index 57) (case insensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
\)
matches the character ) literally (case insensitive)
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
Match a single character present in the list below
[\s-]
? matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy)
\s matches any whitespace character (equivalent to [\r\n\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff])
- matches the character - literally (case insensitive)
This hyphen is treated literally, which might be confusing for others. Consider escaping it or placing at the start or end of the class!
Match a single character present in the list below
[2-9]
2-9 matches a single character in the range between 2 (index 50) and 9 (index 57) (case insensitive)
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
Match a single character present in the list below
[\s-]
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
\d matches a digit (equivalent to [0-9])
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

/
/
gi

Test String