Regular Expressions 101

Save & Share

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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/^\(?(?\'prefix\'\+|(?:0(?:0(?:0|1|9)?|1(?:0|1))?|119)[-. ])?(?\'group\'[1-9])[-. ]?(?\'CC\'[0-9]{0,3})\)?[)-. ](?\'number\'(?:[0-9]+[-. ]?)+)$/m'; $str = '1-719-691-8965 1-803-974-0876 1-688-944-7218 1-945-925-9015 1-644-486-1985 1-949-959-6957 1-989-134-4495 1-789-437-5612 1-759-923-2805 1-108-433-5627 (656) 322-0032 (318) 842-1324 (108) 803-8302 (638) 621-0848 (258) 568-2801 (423) 453-2131 (372) 785-2492 (189) 151-8444 (339) 570-2367 (640) 308-3953 (0110) 348 1534 055 2168 7289 (0151) 725 1366 (0121) 684 2474 0800 243574 055 4684 1647 0800 1111 0894 723 5978 0800 822381 056 5354 9145 (016977) 3324 07624 161240 076 6589 9375 0845 46 42 (013910) 74936 0800 1111 (023) 2043 2875 056 7349 4620 (01082) 153918 0500 298890 +3733 111 04 78 61 38 36 01 37 75 44 65 02 27 33 25 93 03 54 12 98 46 02 65 05 29 43 08 78 84 22 07 05 18 68 87 99 01 28 44 68 61 08 97 83 13 84 05 58 53 92 71 04 97 24 20 43 03 12 51 82 47 (08) 2380 0007 (07) 8293 5212 (04) 1216 5933 (09) 7562 7473 (08) 0719 4870 (09) 9777 4813 (03) 5336 4899 (09) 0165 1310 (07) 3778 1180 (03) 7244 9033 (01) 5422 5928 (01) 7319 1377 (02) 2718 7173 (09) 8648 6765 (02) 2561 3465 (02) 7415 0181 (05) 5450 5084 (09) 9957 6381 (03) 3355 7957 (06) 8709 6724 (0267) 88248907 (039382) 214578 (097) 87594749 (001) 75847459 (039972) 748017 (037590) 069162 (049) 44530022 (066) 23958967 (0860) 13670781 (0209) 31052751 (038947) 213657 (06884) 9075505 (019) 70106155 (036268) 869755 (0296) 22826783 (059) 80297108 (0286) 14276801 (0939) 22673186 (0111) 84734269 (0817) 56797177 050-293-7278 006-438-1474 099-518-8110 030-904-4947 094-043-8752 093-043-7922 017-937-3014 028-770-0387 040-521-6038 090-091-2305 913-6377 1-523-604-1043 1-120-480-2177 1-151-194-4404 966-6015 786-7106 433-9035 989-7973 1-640-644-0966 168-5472 1-530-230-0179 1-238-854-0493 541-4932 1-793-996-2597 771-6231 1-388-639-1864 1-668-361-1245 1-185-371-5208 1-293-175-2379 1-749-679-0982 '; 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