Regular Expressions 101

Save & Share

  • Regex Version: ver. 3
  • 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 = '/^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?)?(?:\:(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([^~\s]*))?(?:(\~[^\s]*?))?$/m'; $str = 'Valid Natural Versions 1.2 1.2.3 1.2.3.4 1.2:123 1.2.3:123 1.2.3.4:123 0.0.4.3~a.b.c 1.2.3.1 10.20.30.40~ 1.1.2.3-prerelease~a.b,c;d:e+meta 1.1.2.4+meta 1.1.2.5+meta-valid 1.1.2.6-valid+meta 1.1.2.7-valid~breaks+meta 1.1.2.4:123+meta 1.1.2.5:123+meta-valid 1.1.2.6:123-valid+meta 1.1.2.7:123-valid~breaks+meta 1.0.0.0-alpha 1.0.0.1~beta 1.0.0.2-alpha.beta 1.0.0.3-alpha22~beta.1 1.0.0.4-alpha.1~~foo+bar 1.0.0.5-alpha0~broken+not 1.0.0.6-alpha+0.valid 1.0.0.7-alpha~a.b_c_somethinglong+build.1_aef.1_its_okay 1.0.0.8-rc.1+build.1 2.0.0.9-rc.1~a,b,c;d,e,f;g:h,i:j+build.123 1.2.3.10-beta 10.2.3.11-DEV-SNAPSHOT 1.2.3.12-SNAPSHOT-123+123~123 1.0.0.13 2.0.0.14 1.1.7.15 2.0.0.16+build.1848 2.0.1.17-alpha.1227 1.0.0.18-alpha+beta 1.2.3.19----RC-SNAPSHOT.12.9.1--.12+788 1.2.3.20----R-S.12.9.1--.12+meta 1.2.3.21----RC-SNAPSHOT.12.9.1--.12 1.0.0.22+0.build.1-rc.10000aaa-kk-0.1 99999999999999999999999.999999999999999999.99999999999999999.999 1.0.0.23-0A.is.legal 1.1.2.4+.123 9.8.7.14+meta+meta 9.8.7.15-whatever+meta+meta 1.2-SNAPSHOT 1.2-RC-SNAPSHOT Invalid Natural Versions 1 1.2: 1.2.3.4-0123 1.2.3.4-0123.0123 1.2.3.4:-0123 +invalid -invalid -invalid+invalid -invalid.01 alpha alpha.beta alpha.beta.1 alpha.1 alpha+beta alpha_beta alpha. alpha.. beta 1.0.0.1-alpha_beta -alpha. 1.0.0.2-alpha.. 1.0.0.3-alpha..1 1.0.0.4-alpha...1 1.0.0.5-alpha....1 1.0.0.6-alpha.....1 1.0.0.7-alpha......1 1.0.0.8-alpha.......1 01.1.1.9 1.01.1.10 1.1.01.11 1.2.3.12.DEV 1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788 -1.0.3.13-gamma+b7718 +justmeta ~just+breaks +meta~broken -beta+meta~still+broken 99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12'; 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