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

/
/
g

Test String

Code Generator

Generated Code

$re = '/.*\.v\n/'; $str = 'ab. d d b c d /home/geli/Projects/coq/book-SoftwareFoundations/lf/ver5.3/lf: total used in directory 6960 available 156637104 drwxr-xr-x 3 geli geli 28672 Oct 14 01:19 . drwxrwxr-x 3 geli geli 4096 Sep 29 00:59 .. -rw-r--r-- 1 geli geli 4030 Sep 29 01:05 .Auto.aux -rw-rw-r-- 1 geli geli 27997 Sep 29 01:05 Auto.glob -rw-r--r-- 1 geli geli 114710 Sep 7 00:46 Auto.html -rw-r--r-- 1 geli geli 231 Sep 29 01:05 .AutoTest.aux -rw-rw-r-- 1 geli geli 488 Sep 29 01:05 AutoTest.glob -rw-r--r-- 1 geli geli 716 Sep 7 00:46 AutoTest.v -rw-rw-r-- 1 geli geli 146 Sep 29 01:05 AutoTest.v.d -rw-rw-r-- 1 geli geli 25563 Sep 29 01:05 AutoTest.vo -rw-r--r-- 1 geli geli 21688 Sep 7 00:46 Auto.v -rw-rw-r-- 1 geli geli 101 Sep 29 01:05 Auto.v.d -rw-rw-r-- 1 geli geli 106413 Sep 29 01:05 Auto.vo -rw-r--r-- 1 geli geli 7963 Sep 29 01:05 .Basics.aux -rw-rw-r-- 1 geli geli 25333 Sep 29 01:05 Basics.glob -rw-r--r-- 1 geli geli 163893 Sep 7 00:46 Basics.html -rw-r--r-- 1 geli geli 1765 Sep 29 01:05 .BasicsTest.aux -rw-rw-r-- 1 geli geli 13920 Sep 29 01:05 BasicsTest.glob -rw-r--r-- 1 geli geli 5495 Sep 7 00:46 BasicsTest.v -rw-rw-r-- 1 geli geli 122 Sep 29 01:05 BasicsTest.v.d -rw-rw-r-- 1 geli geli 2185 Sep 29 01:05 BasicsTest.vo -rw-r--r-- 1 geli geli 49006 Oct 14 01:19 Basics.v -rw-r--r-- 1 geli geli 48945 Sep 29 10:03 Basics.v~ -rw-rw-r-- 1 geli geli 73 Sep 29 01:05 Basics.v.d -rw-rw-r-- 1 geli geli 33638 Sep 29 01:05 Basics.vo -rw-r--r-- 1 geli geli 137 Sep 29 01:05 .Bib.aux -rw-rw-r-- 1 geli geli 45 Sep 29 01:05 Bib.glob -rw-r--r-- 1 geli geli 3680 Sep 7 00:46 Bib.html -rw-r--r-- 1 geli geli 230 Sep 29 01:05 .BibTest.aux -rw-rw-r-- 1 geli geli 335 Sep 29 01:05 BibTest.glob -rw-r--r-- 1 geli geli 552 Sep 7 00:46 BibTest.v -rw-rw-r-- 1 geli geli 98 Sep 29 01:05 BibTest.v.d -rw-rw-r-- 1 geli geli 2070 Sep 29 01:05 BibTest.vo -rw-r--r-- 1 geli geli 1265 Sep 7 00:46 Bib.v -rw-rw-r-- 1 geli geli 55 Sep 29 01:05 Bib.v.d -rw-rw-r-- 1 geli geli 1253 Sep 29 01:05 Bib.vo drwxr-xr-x 5 geli geli 4096 Sep 29 00:59 common -rw-r--r-- 1 geli geli 245827 Sep 7 00:46 coqindex.html -rw-rw-r-- 1 geli geli 90 Sep 29 01:02 _CoqProject~ -rw-rw-r-- 1 geli geli 72 Sep 29 01:04 _CoqProject.dist -rw-r--r-- 1 geli geli 1886 Sep 7 00:46 .depend -rw-r--r-- 1 geli geli 33848 Sep 7 00:46 deps.gif -rw-r--r-- 1 geli geli 3552 Sep 7 00:46 deps.html -rw-r--r-- 1 geli geli 2058 Sep 7 00:46 deps.map -rw-r--r-- 1 geli geli 144 Sep 29 01:05 .Extraction.aux -rw-rw-r-- 1 geli geli 437 Sep 29 01:05 Extraction.glob -rw-r--r-- 1 geli geli 10550 Sep 7 00:46 Extraction.html -rw-r--r-- 1 geli geli 4506 Sep 7 00:46 Extraction.v -rw-rw-r-- 1 geli geli 182 Sep 29 01:05 Extraction.v.d -rw-rw-r-- 1 geli geli 25877 Sep 29 01:05 Extraction.vo -rw-r--r-- 1 geli geli 4577 Sep 29 01:05 imp1.ml -rw-r--r-- 1 geli geli 1255 Sep 29 01:05 imp1.mli -rw-r--r-- 1 geli geli 4447 Sep 29 01:05 imp2.ml -rw-r--r-- 1 geli geli 1200 Sep 29 01:05 imp2.mli -rw-r--r-- 1 geli geli 7523 Sep 29 01:05 .Imp.aux -rw-r--r-- 1 geli geli 1219 Sep 29 01:05 .ImpCEvalFun.aux -rw-rw-r-- 1 geli geli 13580 Sep 29 01:05 ImpCEvalFun.glob -rw-r--r-- 1 geli geli 73635 Sep 7 00:46 ImpCEvalFun.html -rw-r--r-- 1 geli geli 12575 Sep 7 00:46 ImpCEvalFun.v -rw-rw-r-- 1 geli geli 143 Sep 29 01:05 ImpCEvalFun.v.d -rw-rw-r-- 1 geli geli 54914 Sep 29 01:05 ImpCEvalFun.vo -rw-r--r-- 1 geli geli 993 Sep 7 00:46 impdriver.ml -rw-rw-r-- 1 geli geli 64308 Sep 29 01:05 Imp.glob -rw-r--r-- 1 geli geli 264297 Sep 7 00:46 Imp.html -rw-r--r-- 1 geli geli 100049 Sep 29 01:05 imp.ml -rw-r--r-- 1 geli geli 3541 Sep 29 01:05 imp.mli -rw-r--r-- 1 geli geli 1261 Sep 29 01:05 .ImpParser.aux -rw-rw-r-- 1 geli geli 40036 Sep 29 01:05 ImpParser.glob -rw-r--r-- 1 geli geli 98096 Sep 7 00:46 ImpParser.html -rw-r--r-- 1 geli geli 13905 Sep 7 00:46 ImpParser.v -rw-rw-r-- 1 geli geli 131 Sep 29 01:05 ImpParser.v.d -rw-rw-r-- 1 geli geli 217451 Sep 29 01:05 ImpParser.vo -rw-r--r-- 1 geli geli 62340 Sep 29 17:37 Imp.v -rw-r--r-- 1 geli geli 62126 Sep 7 00:46 Imp.v~ -rw-rw-r-- 1 geli geli 76 Sep 29 01:05 Imp.v.d -rw-rw-r-- 1 geli geli 128121 Sep 29 01:05 Imp.vo -rw-r--r-- 1 geli geli 2532 Sep 7 00:46 index.html -rw-r--r-- 1 geli geli 2013 Sep 29 01:05 .IndPrinciples.aux -rw-rw-r-- 1 geli geli 7273 Sep 29 01:05 IndPrinciples.glob -rw-r--r-- 1 geli geli 97705 Sep 7 00:46 IndPrinciples.html -rw-r--r-- 1 geli geli 241 Sep 29 01:05 .IndPrinciplesTest.aux -rw-rw-r-- 1 geli geli 448 Sep 29 01:05 IndPrinciplesTest.glob -rw-r--r-- 1 geli geli 623 Sep 7 00:46 IndPrinciplesTest.v -rw-rw-r-- 1 geli geli 215 Sep 29 01:05 IndPrinciplesTest.v.d -rw-rw-r-- 1 geli geli 25719 Sep 29 01:05 IndPrinciplesTest.vo -rw-r--r-- 1 geli geli 26206 Sep 7 00:46 IndPrinciples.v -rw-rw-r-- 1 geli geli 152 Sep 29 01:05 IndPrinciples.v.d -rw-rw-r-- 1 geli geli 44392 Sep 29 01:05 IndPrinciples.vo -rw-r--r-- 1 geli geli 10063 Sep 29 01:05 .IndProp.aux -rw-rw-r-- 1 geli geli 47576 Sep 29 01:05 IndProp.glob -rw-r--r-- 1 geli geli 246242 Sep 7 00:46 IndProp.html -rw-r--r-- 1 geli geli 56917 Sep 7 00:46 IndProp.v -rw-rw-r-- 1 geli geli 102 Sep 29 01:05 IndProp.v.d -rw-rw-r-- 1 geli geli 87009 Sep 29 01:05 IndProp.vo -rw-r--r-- 1 geli geli 4092 Sep 29 01:05 .Induction.aux -rw-rw-r-- 1 geli geli 13616 Sep 29 01:05 Induction.glob -rw-r--r-- 1 geli geli 52248 Sep 7 00:46 Induction.html -rw-r--r-- 1 geli geli 722 Sep 29 01:05 .InductionTest.aux -rw-rw-r-- 1 geli geli 6490 Sep 29 01:05 InductionTest.glob -rw-r--r-- 1 geli geli 2779 Sep 7 00:46 InductionTest.v -rw-rw-r-- 1 geli geli 171 Sep 29 01:05 InductionTest.v.d -rw-rw-r-- 1 geli geli 2171 Sep 29 01:05 InductionTest.vo -rw-r--r-- 1 geli geli 21215 Sep 7 00:46 Induction.v -rw-rw-r-- 1 geli geli 116 Sep 29 01:05 Induction.v.d -rw-rw-r-- 1 geli geli 8562 Sep 29 01:05 Induction.vo -rw-r--r-- 1 geli geli 1043 Sep 7 00:46 LICENSE -rw-r--r-- 1 geli geli 11086 Sep 29 01:05 .Lists.aux -rw-rw-r-- 1 geli geli 44766 Sep 29 01:05 Lists.glob -rw-r--r-- 1 geli geli 153575 Sep 7 00:46 Lists.html -rw-r--r-- 1 geli geli 4028 Sep 29 01:05 .ListsTest.aux -rw-rw-r-- 1 geli geli 35332 Sep 29 01:05 ListsTest.glob -rw-r--r-- 1 geli geli 10930 Sep 7 00:46 ListsTest.v -rw-rw-r-- 1 geli geli 145 Sep 29 01:05 ListsTest.v.d -rw-rw-r-- 1 geli geli 2351 Sep 29 01:05 ListsTest.vo -rw-r--r-- 1 geli geli 35875 Sep 7 00:46 Lists.v -rw-rw-r-- 1 geli geli 98 Sep 29 01:05 Lists.v.d -rw-rw-r-- 1 geli geli 43108 Sep 29 01:05 Lists.vo -rw-r--r-- 1 geli geli 13156 Sep 29 01:05 .Logic.aux -rw-rw-r-- 1 geli geli 45782 Sep 29 01:05 Logic.glob -rw-r--r-- 1 geli geli 199398 Sep 7 00:46 Logic.html -rw-r--r-- 1 geli geli 2332 Sep 29 01:05 .LogicTest.aux -rw-rw-r-- 1 geli geli 33150 Sep 29 01:05 LogicTest.glob -rw-r--r-- 1 geli geli 9562 Sep 7 00:46 LogicTest.v -rw-rw-r-- 1 geli geli 141 Sep 29 01:05 LogicTest.v.d -rw-rw-r-- 1 geli geli 3637 Sep 29 01:05 LogicTest.vo -rw-r--r-- 1 geli geli 50242 Sep 7 00:46 Logic.v -rw-rw-r-- 1 geli geli 94 Sep 29 01:05 Logic.v.d -rw-rw-r-- 1 geli geli 75770 Sep 29 01:05 Logic.vo -rw-r--r-- 1 geli geli 8464 Sep 7 00:46 Makefile -rw-r--r-- 1 geli geli 3725 Sep 29 01:05 .Maps.aux -rw-rw-r-- 1 geli geli 11576 Sep 29 01:05 Maps.glob -rw-r--r-- 1 geli geli 63258 Sep 7 00:46 Maps.html -rw-r--r-- 1 geli geli 371 Sep 29 01:05 .MapsTest.aux -rw-rw-r-- 1 geli geli 2993 Sep 29 01:05 MapsTest.glob -rw-r--r-- 1 geli geli 1488 Sep 7 00:46 MapsTest.v -rw-rw-r-- 1 geli geli 106 Sep 29 01:05 MapsTest.v.d -rw-rw-r-- 1 geli geli 24201 Sep 29 01:05 MapsTest.vo -rw-r--r-- 1 geli geli 12030 Sep 7 00:46 Maps.v -rw-rw-r-- 1 geli geli 61 Sep 29 01:05 Maps.v.d -rw-rw-r-- 1 geli geli 41736 Sep 29 01:05 Maps.vo -rw-r--r-- 1 geli geli 11574 Sep 29 01:05 .Poly.aux -rw-rw-r-- 1 geli geli 47361 Sep 29 01:05 Poly.glob -rw-r--r-- 1 geli geli 178578 Sep 7 00:46 Poly.html -rw-r--r-- 1 geli geli 3165 Sep 29 01:05 .PolyTest.aux -rw-rw-r-- 1 geli geli 29738 Sep 29 01:05 PolyTest.glob -rw-r--r-- 1 geli geli 9007 Sep 7 00:46 PolyTest.v -rw-rw-r-- 1 geli geli 129 Sep 29 01:05 PolyTest.v.d -rw-rw-r-- 1 geli geli 2430 Sep 29 01:05 PolyTest.vo -rw-r--r-- 1 geli geli 38772 Sep 7 00:46 Poly.v -rw-rw-r-- 1 geli geli 84 Sep 29 01:05 Poly.v.d -rw-rw-r-- 1 geli geli 67542 Sep 29 01:05 Poly.vo -rw-r--r-- 1 geli geli 144 Sep 29 01:05 .Postscript.aux -rw-rw-r-- 1 geli geli 52 Sep 29 01:05 Postscript.glob -rw-r--r-- 1 geli geli 6136 Sep 7 00:46 Postscript.html -rw-r--r-- 1 geli geli 237 Sep 29 01:05 .PostscriptTest.aux -rw-rw-r-- 1 geli geli 392 Sep 29 01:05 PostscriptTest.glob -rw-r--r-- 1 geli geli 566 Sep 7 00:46 PostscriptTest.v -rw-rw-r-- 1 geli geli 154 Sep 29 01:05 PostscriptTest.v.d -rw-rw-r-- 1 geli geli 2098 Sep 29 01:05 PostscriptTest.vo -rw-r--r-- 1 geli geli 3655 Sep 7 00:46 Postscript.v -rw-rw-r-- 1 geli geli 97 Sep 29 01:05 Postscript.v.d -rw-rw-r-- 1 geli geli 1267 Sep 29 01:05 Postscript.vo -rw-r--r-- 1 geli geli 141 Sep 29 01:05 .Preface.aux -rw-rw-r-- 1 geli geli 49 Sep 29 01:05 Preface.glob -rw-r--r-- 1 geli geli 23910 Sep 7 00:46 Preface.html -rw-r--r-- 1 geli geli 234 Sep 29 01:05 .PrefaceTest.aux -rw-rw-r-- 1 geli geli 368 Sep 29 01:05 PrefaceTest.glob -rw-r--r-- 1 geli geli 560 Sep 7 00:46 PrefaceTest.v -rw-rw-r-- 1 geli geli 130 Sep 29 01:05 PrefaceTest.v.d -rw-rw-r-- 1 geli geli 2086 Sep 29 01:05 PrefaceTest.vo -rw-r--r-- 1 geli geli 19921 Sep 7 00:46 Preface.v -rw-rw-r-- 1 geli geli 79 Sep 29 01:05 Preface.v.d -rw-rw-r-- 1 geli geli 1261 Sep 29 01:05 Preface.vo -rw-r--r-- 1 geli geli 2500 Sep 29 01:05 .ProofObjects.aux -rw-rw-r-- 1 geli geli 10291 Sep 29 01:05 ProofObjects.glob -rw-r--r-- 1 geli geli 71057 Sep 7 00:46 ProofObjects.html -rw-r--r-- 1 geli geli 21209 Sep 7 00:46 ProofObjects.v -rw-rw-r-- 1 geli geli 136 Sep 29 01:05 ProofObjects.v.d -rw-rw-r-- 1 geli geli 40133 Sep 29 01:05 ProofObjects.vo -rw-r--r-- 1 geli geli 646 Sep 7 00:46 README -rw-r--r-- 1 geli geli 3137 Sep 29 01:05 .Rel.aux -rw-rw-r-- 1 geli geli 12825 Sep 29 01:05 Rel.glob -rw-r--r-- 1 geli geli 65837 Sep 7 00:46 Rel.html -rw-r--r-- 1 geli geli 12721 Sep 7 00:46 Rel.v -rw-rw-r-- 1 geli geli 82 Sep 29 01:05 Rel.v.d -rw-rw-r-- 1 geli geli 41219 Sep 29 01:05 Rel.vo -rw-r--r-- 1 geli geli 6984 Sep 29 01:05 .Tactics.aux -rw-rw-r-- 1 geli geli 30916 Sep 29 01:05 Tactics.glob -rw-r--r-- 1 geli geli 170622 Sep 7 00:46 Tactics.html -rw-r--r-- 1 geli geli 864 Sep 29 01:05 .TacticsTest.aux -rw-rw-r-- 1 geli geli 11356 Sep 29 01:05 TacticsTest.glob -rw-r--r-- 1 geli geli 4193 Sep 7 00:46 TacticsTest.v -rw-rw-r-- 1 geli geli 151 Sep 29 01:05 TacticsTest.v.d -rw-rw-r-- 1 geli geli 2360 Sep 29 01:05 TacticsTest.vo -rw-r--r-- 1 geli geli 38414 Sep 7 00:46 Tactics.v -rw-rw-r-- 1 geli geli 100 Sep 29 01:05 Tactics.v.d -rw-rw-r-- 1 geli geli 25778 Sep 29 01:05 Tactics.vo -rw-r--r-- 1 geli geli 17052 Sep 7 00:46 toc.html '; 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