Regular Expressions 101

Save & Share

  • Regex Version: ver. 4
  • 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

/
/
mgD

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/.*(\w{4}\d{7}).*/mD'; $str = 'UNB+UNOA:2+RCW OPS CENTER+TERMINAL+180808:1519+1533741570C3ED+++++RCW OPS CENTER\'UNH+01533741570BAP+BAPLIE:D:95B:UN:SMDG22\'BGM++CAPSTAN4.20180808151930+9\'DTM+137 1808081519UTC:301\'TDT+20+081S+++HSD:172:166+++9V7575:103:ZZZ:xxxx xxx\'LOC+5+BRSSA:139:6\'LOC+61+COCTG:139:6\'DTM+178:1808090412 :201\'DTM+133:1808091512:201\'DTM+132:1808180041:201\'RFF+VON:081N\'LOC+147+0380412::5\'MEA+WT++KGM:29515\'LOC+9+BRSSA:139:6+TECSV\'LOC+11+COCTG:139:6+TCC\'LOC+83+DOHAI:139:6\'RFF+BM:1\'EQD+CN+ SUDU8505087+45G1+++5\'NAD+CA+HSD:172:20\'LOC+147+0380312::5\'MEA+WT++KGM:29586\'LOC+9+BRSSA:139:6+TECSV\'LOC+11+COCTG:139:6+TCC\'LOC+83+DOCAU:139:6\'RFF+BM:1\'EQD+CN+ UACU5363691+45G1+++5\'NAD+CA+HLC:172:20\'LOC+147+0380212::5\'MEA+WT++KGM:29591\'LOC+9+BRSSA:139:6+TECSV\'LOC+11+COCTG:139:6+TCC\'LOC+83+COCTG:139:6\'RFF+BM:1\'EQD+CN+ TGHU9702812+45G1+++5\'NAD+CA+MSC:172:20\'LOC+147+0380112::5\'MEA+WT++KGM:29616\'LOC+9+BRSSA:139:6+TECSV\'LOC+11+COCTG:139:6+TCC\'LOC+83+DOCAU:139:6\'RFF+BM:1\'EQD+CN+ HLXU6240079+45G1+++5\'NAD+CA+HLC:172:20\'LOC+147+0380414::5\'MEA+WT++KGM:29476\'LOC+9+BRSSA:139:6+TECSV\'LOC+11+COCTG:139:6+TCC\'LOC+83+PRSJU:139:6\'RFF+BM:1\'EQD+CN+ HASU4556735+45G1+++5\'NAD+CA+HSD:172:20\'LOC+147+0380314::5\'MEA+WT++KGM:29476\'LOC+9+BRSSA:139:6+TECSV\'LOC+11+COCTG:139:6+TCC\'LOC+83+DOHAI:139:6\'RFF+BM:1\'EQD+CN+ SUDU6787839+45G1+++5\'NAD+CA+HSD:172:20\'LOC+147+0380214::5\'MEA+WT++KGM:29481\'LOC+9+BRSSA:139:6+TECSV\'LOC+11+COCTG:139:6+TCC\'LOC+83+COCTG:139:6\'RFF+BM:1\'EQD+CN+...'; $subst = "$1\r\n"; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$result;

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