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 (1)

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
No Match

r"
"
mg

Test String

Code Generator

Generated Code

const regex = new RegExp('^\\(?(?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]+[-. ]?)+)$', 'mg') const str = `#phone number testing 001 37156 (+213) 44 00 1-684 11 000 376 124 +244 111 +1-264 111 010-672-11 1-268 1111111 +44-111 44-111 +1-719-691-8965 1-719-691-8965 +1719-691-8965 1719-691-8965 17196918965 1.719.691.8965 1 719 691 8965 0021222 0011222 0011222 +401111 +4241111 +5111 +3716888 +36898989 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 +561111 +374 +297 +247 +61 +672 +43 +994 +1-242 +973 +880 +1-246 +1-268 +375 +32 +501 +229 +1-441 +975 +591 +387 +267 +55 +1-284 +673 +359 +226 +257 +855 +237 +1 +238 +1-345 +236 +235 +64 +56 +86 +53 +61 +57 +269 +242 +243 +682 +506 +225 +385 +53 +5399 +599 +357 +420 +45 +246 +253 +1-767 +1-809 1-829 +670 +56 +593 +20 +503 +8812 +8813 +88213 +240 +291 +372 +251 +500 +298 +679 +358 +33 +596 +594 +689 +241 +220 +995 +49 +233 +350 +881 +30 +299 +1-473 +590 +1-671 +5399 +502 +245 +224 +592 +509 +504 +852 +36 +354 +91 +62 +871 +874 +873 +872 +870 +800 +808 +98 +964 +353 +8816 +8817 +972 +39 +1-876 +81 +962 +7 +254 +686 +850 +82 +965 +996 +856 +371 +961 +266 +231 +218 +423 +370 +352 +853 +389 +261 +265 +60 +960 +223 +356 +692 +596 +222 +230 +269 +52 +691 +1-808 +373 +377 +976 +382 +1-664 +212 +258 +95 +264 +674 +977 +31 +599 +1-869 +687 +64 +505 +227 +234 +683 +672 +1-670 +1-1 +47 +968 +92 +680 +970 +507 +675 +595 +51 +63 +48 +351 ++1-787 or +1-939 +974 +262 +40 +7 +250 +290 +1-869 +1-758 +508 +1-784 +685 +378 +239 +966 +221 +381 +248 +232 +65 +421 +386 +677 +252 +27 +34 +94 +249 +597 +268 +46 +41 +963 +886 +992 +255 +66 +88216 +670 +228 +690 +676 +1-868 +216 +90 +993 +1-649 +688 +256 +380 +971 +44 +1 +1-340 +878 +598 +998 +678 ++39, +379 +58 +84 +808 +681 +967 +260 +255 +263 `; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions