Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new 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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/^(([+]{1}[1-9]{1}[0-9]{0,2}[ ]{1}([1-9]{1}[0-9]{1,4}){1}[ ]{1}([1-9]{1}[0-9]{2,6}){1}([ -][0-9]{1,5})?)|([0]{1}[1-9]{1}[0-9]{1,4}[ ]{1}[0-9]{1,8}([ -][0-9]{1,8})?)?)/m'; $str = '06429 1111 06901 306180 06429 231 0800 3301000 0179 1111111 0873 376461 03748 37682358 05444 347687-350 0764 812632-41 0180 2 12334 0800 5 23234213 +49 6429 1111 +49 39857 2530 +55 11 2666-0054 +300 11 2666-0054 +49 641 20106 0 +49 641 20106 +49 30 3432622-113 ------ +300 11 0000-0000 (06442) 3933023 (02852) 5996-0 (042) 1818 87 9919 06442 / 3893023 06442 / 38 93 02 3 06442/3839023 042/ 88 17 890 0 +49 221 - 542194 79 +49 (221) - 542944 79 0 52 22 - 9 50 93 10 +49(0)121-79536 - 77 +49(0)2221-39938-113 +49 (0) 1739 906-44 +49 (173) 1799 806-44 0173173990644 0214154914479 01517953677 +491517953677 015777953677 02162 - 54 91 44 79 (02162) 54 91 44 79 saddsadasdasd asdasd asdasd asdasd asd asdasd kjn asohas asdoiasd 23434 234 234 23 323 23434 234----234 ///// ---- // id8834 3493934 //'; 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