Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Fork Regex
    ctrl+s
  • Add to Community Library

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression

/
/
mg

Test String

Code Generator

Generated Code

$re = '/^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$/m'; $str = '843-626-0302 785-333-8041 863-587-8815 658-875-1516 580-449-7703 962-731-8512 878-924-0235 756-713-2113 888-923-3435 308-586-0293 598-683-0441 675-628-3515 209-797-3451 771-440-4352 193-953-1253 (253) 6509483 (347) 8127332 (754) 7719425 (213) 5265535 (402) 1977514 (735) 7162662 (676) 9793937 (611) 4247674 (604) 2130247 682 207 3739 357 908 6923 493 219 9082 980 154 6402 294 121 8026 561 255 8516 477 860 5769 776 644 9851 509 625 7679 +48 793 766 3373 +86 806 716 0094 +86 585 664 5867 +62 737 389 6574 +420 222 563 6738 +7 260 995 8947 +993 171 621 0950 +62 646 616 4139 +98 714 968 6953 +212 967 232 9606 +7 (748) 109-5579 +98 (333) 697-0263 +86 (668) 939-6348 +56 (397) 682-4831 +86 (907) 582-5004 +86 (808) 602-5582 +86 (601) 453-7045 +86 (176) 350-1980 +57 (982) 617-5389 +7 (384) 102-7843 +66-226-146-9224 +972-270-501-4701 +86-865-794-9776 +66-237-386-9139 +62-104-622-7544 +856-256-504-8882 +1-882-964-4797 +33-602-657-9024 +60-548-777-0851 +86-982-155-6812 386(570)720-5471 1(585)244-8353 244(462)323-3908 381(383)564-2517 55(239)311-9045 86(684)401-0051 82(252)838-5913 233(739)838-8421 1(869)479-5451 53(687)450-7439 62(885)232-9247 5038954693 5523566227 2835852181 4871138589 6604677771 5814400542 1149880242 8619976834 5985388913 '; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php