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 = '/LOC\+11[^L]*(?:L(?!OC\+11)[^L]*)*/m'; $str = '> NAD+ST+14::92++Test\' LOC+11+KOD23277::92\' LOC+7+D77::92:Test\' LIN+1++ > test AP:IN\'IMD+F++12::272:K > RIPPsadasdRIEM\'RFF+ON:EN10514492\'RFF+AAN:501\' > DTM+171:20220309:102\'RFF+AIF:500\'DTM+171:20220305:102\'CTA+SC+12414:test, > test\'COM+melweasdsaanigge.frasdasdasdaicke1@test.de:EM\' > COM+?+49-561-490-4173:TE\'COM+?+49-561-490-84173:FX\' QTY+83:1000:PCE\' > QTY+70:66850:PCE\'DTM+51:20080101:102\' > QTY+72:0:PCE\'DTM+52:20080101:102\' > QTY+194:1000:PCE\'DTM+50:20220224:102\' > RFF+AAU:2143276\'DTM+171:20220218:102\' > QTY+194:1000:PCE\'DTM+50:20220202:102\' > RFF+AAU:2138944\'DTM+171:20220131:102\' > QTY+194:1000:PCE\'DTM+50:20220105:102\' > RFF+AAU:2138943\'DTM+171:20220103:102\' SCC+24\' > QTY+113:1000:PCE\'DTM+2:20220412:102\' > QTY+113:1000:PCE\'DTM+2:20220503:102\' > QTY+113:1000:PCE\'DTM+64:20220530:102\'DTM+63:20220605:102\' > QTY+113:1000:PCE\'DTM+64:20220620:102\'DTM+63:20220626:102\' > QTY+113:1000:PCE\'DTM+64:20220711:102\'DTM+63:20220717:102\' > QTY+113:1000:PCE\'DTM+64:20220801:102\'DTM+63:20220807:102\' GEI+3+37\' > > NAD+ST+14::92++test\' LOC+11+KOD823226::92\' LOC+7+D86::92:Test\' LIN+2++ > test H:IN\'IMD+F++12::272:K > RIPPRIEM\'RFF+ON:EN10662318\'RFF+AAN:266\'DTM+171:20220309:102\' > RFF+AIF:265\'DTM+171:20220305:102\'CTA+SC+12414:test, > test\'COM+test.test@test.de:EM\' > COM+?+49-561-490-4173:TE\'COM+?+49-561-490-84173:FX\' QTY+83:200:PCE\' > QTY+70:14319:PCE\'DTM+51:20100101:102\' > QTY+72:0:PCE\'DTM+52:20100101:102\' QTY+194:200:PCE\'DTM+50:20220126:102\' > RFF+AAU:2146871\'DTM+171:20220121:102\' > QTY+194:200:PCE\'DTM+50:20211210:102\'RFF+AAU:2146914\'DTM+171:20211209:102\' QTY+194:200:PCE\'DTM+50:20211129:102\'RFF+AAU:2139927\'DTM+171:20211124:102\'SCC+24\' > QTY+113:200:PCE\'DTM+2:20220503:102\' > QTY+113:200:PCE\'DTM+64:20220606:102\'DTM+63:20220612:102\' > QTY+113:200:PCE\'DTM+64:20220718:102\'DTM+63:20220724:102\' > QTY+113:200:PCE\'DTM+64:20220829:102\'DTM+63:20220904:102\' > QTY+113:200:PCE\'DTM+64:20221010:102\'DTM+63:20221016:102\' > > UNT+142+1\'UNZ+1+2756\''; 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