Regular Expressions 101

Save & Share


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


  • Match
  • Substitution
  • List
  • Unit Tests (1)


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
  • A character except: a, b or c
  • A character in the range: a-z
  • A character not in the range: a-z
  • A character in the range: a-z or A-Z
  • Any single character
  • Alternate - match either a or b
  • Any whitespace character
  • Any non-whitespace character
  • Any digit
  • Any non-digit
  • Any word character
  • Any non-word character
  • Match everything enclosed
  • Capture everything enclosed
  • Zero or one of a
  • Zero or more of a
  • One or more of a
  • Exactly 3 of a
  • 3 or more of a
  • Between 3 and 6 of a
  • Start of string
  • End of string
  • A word boundary
  • Non-word boundary

Regular Expression
No Match


Test String

Code Generator

Generated Code

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"^\(?(?P<prefix>(?=1)|\+|(?:0(?:0(?:0|1|9)?|1(?:0|1))?|119))[-. ]?\(?(?P<CC>1([-. ]?)[0-9]{3}|2(?:0|[0-9]{2})|3(?:[0-469]|[0-9]{2})|4(?:[013-9]|[0-9]{2})|5(?:[1-8]|[0-9]{2})|6(?:[0-6]|[0-9]{2})|7(?:[-. ]?[67]|[0-9]{3})|8(?:[1246]|[0-9]{2})|9(?:[0-58]|[0-9]{2}))(?:\)?[-. ])?(?P<number>(?:[0-9]+[-. ]?)+)$" test_str = ("#phone number testing \n" "001 37156\n" "(+213) 44\n" "00 1-684 11\n" "000 376 124\n" "+244 111\n" "+1-264 111\n" "010-672-11\n" "1-268 1111111\n\n" "+44-111\n" "44-111\n" "+1-719-691-8965\n" "1-719-691-8965\n\n" "+1719-691-8965\n" "1719-691-8965\n" "17196918965\n" "1.719.691.8965\n" "1 719 691 8965\n\n" "0021222\n" "0011222\n" "0011222\n\n" "+401111\n" "+4241111\n" "+5111\n\n" "+3716888\n" "+36898989\n\n" "1-803-974-0876\n" "1-688-944-7218\n" "1-945-925-9015\n" "1-644-486-1985\n" "1-949-959-6957\n" "1-989-134-4495\n" "1-789-437-5612\n" "1-759-923-2805\n" "1-108-433-5627\n" "(656) 322-0032\n" "(318) 842-1324\n" "(108) 803-8302\n" "(638) 621-0848\n" "(258) 568-2801\n" "(423) 453 2131\n" "(372) 785.2492\n" "(189) 151 8444\n" "(339) 570.2367\n" "(640) 308-3953\n" "+561111\n" "+374\n" "+297\n" "+247\n" "+61\n" "+672\n" "+43\n" "+994\n" "+1-242\n" "+973\n" "+880\n" "+1-246\n" "+1-268\n" "+375\n" "+32\n" "+501\n" "+229\n" "+1-441\n" "+975\n" "+591\n" "+387\n" "+267\n" "+55\n" "+1-284\n" "+673\n" "+359\n" "+226\n" "+257\n" "+855\n" "+237\n" "+1\n" "+238\n" "+1-345\n" "+236\n" "+235\n" "+64\n" "+56\n" "+86\n" "+53\n\n" "+61\n" "+57\n" "+269\n" "+242\n" "+243\n" "+682\n" "+506\n" "+225\n" "+385\n" "+53\n" "+5399\n" "+599\n" "+357\n" "+420\n" "+45\n" "+246\n" "+253\n" "+1-767\n" "+1-809\n" "1-829\n" "+670\n" "+56\n" "+593\n" "+20\n" "+503\n" "+8812\n" "+8813\n" "+88213\n" "+240\n" "+291\n" "+372\n" "+251\n" "+500\n" "+298\n" "+679\n" "+358\n" "+33\n" "+596\n" "+594\n" "+689\n" "+241\n" "+220\n" "+995\n" "+49\n" "+233\n" "+350\n" "+881\n\n\n\n\n\n" "+30\n" "+299\n" "+1-473\n" "+590\n" "+1-671\n" "+5399\n" "+502\n" "+245\n" "+224\n" "+592\n" "+509\n" "+504\n" "+852\n" "+36\n\n" "+354\n" "+91\n" "+62\n" "+871\n" "+874\n" "+873\n" "+872\n" "+870\n\n" "+800\n" "+808\n" "+98\n" "+964\n" "+353\n" "+8816\n" "+8817\n" "+972\n" "+39\n" "+1-876\n" "+81\n" "+962\n" "+7\n" "+254\n" "+686\n" "+850\n" "+82\n" "+965\n" "+996\n" "+856\n" "+371\n" "+961\n" "+266\n" "+231\n" "+218\n" "+423\n" "+370\n" "+352\n" "+853\n" "+389\n" "+261\n" "+265\n" "+60\n" "+960\n" "+223\n" "+356\n" "+692\n" "+596\n" "+222\n" "+230\n" "+269\n" "+52\n" "+691\n" "+1-808\n" "+373\n" "+377\n" "+976\n" "+382\n" "+1-664\n" "+212\n" "+258\n" "+95\n" "+264\n" "+674\n" "+977\n" "+31\n" "+599\n" "+1-869\n" "+687\n" "+64\n" "+505\n" "+227\n" "+234\n" "+683\n" "+672\n" "+1-670\n" "+1-1\n" "+47\n" "+968\n" "+92\n" "+680\n" "+970\n" "+507\n" "+675\n" "+595\n" "+51\n" "+63\n" "+48\n" "+351\n" "++1-787 or +1-939\n" "+974\n" "+262\n" "+40\n" "+7\n" "+250\n" "+290\n" "+1-869\n" "+1-758\n" "+508\n" "+1-784\n" "+685\n" "+378\n" "+239\n" "+966\n" "+221\n" "+381\n" "+248\n" "+232\n" "+65\n" "+421\n" "+386\n" "+677\n" "+252\n" "+27\n" "+34\n" "+94\n" "+249\n" "+597\n" "+268\n" "+46\n" "+41\n" "+963\n" "+886\n" "+992\n" "+255\n" "+66\n" "+88216\n" "+670\n" "+228\n" "+690\n" "+676\n" "+1-868\n" "+216\n" "+90\n" "+993\n" "+1-649\n" "+688\n" "+256\n" "+380\n" "+971\n" "+44\n" "+1\n" "+1-340\n" "+878\n" "+598\n" "+998\n" "+678\n" "++39, +379\n" "+58\n" "+84\n" "+808\n" "+681\n" "+967\n" "+260\n" "+255\n" "+263\n") matches = re.finditer(regex, test_str, re.MULTILINE) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

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: