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

Substitution

Processing...

Code Generator

Generated Code

const regex = />[^<^\w]+</g; // Alternative syntax using RegExp constructor // const regex = new RegExp('>[^<^\\w]+<', 'g') const str = `<?xml version="1.0" encoding="UTF-8"?> <ORDRSP>     <UNH>         <E0062>MSG127</E0062>         <S009>             <E0065>ORDRSP</E0065>             <E0052>D</E0052>             <E0054>01B</E0054>             <E0051>UN</E0051>             <E0057>EAN010</E0057>         </S009>     </UNH>     <BGM>         <C002>             <E1001>231</E1001>         </C002>         <C106>             <E1004>ORSP12856</E1004>         </C106>         <E1225>4</E1225>     </BGM>     <DTM>         <C507>             <E2005>137</E2005>             <E2380>20041230</E2380>             <E2379>102</E2379>         </C507>     </DTM> <DTM>         <C507> <E2005>55</E2005> <E2380>20041230</E2380> <E2379>102</E2379> </C507>     </DTM> <FTX> <E4451>TRA</E4451> <C108> <E4440>МАШ:3;30.06.2011,07:00-11:00,001;30.06.2011,17:30-18:00,001;29.06.2011,12:00-14:00,001;</E4440> </C108> </FTX>     <SG1>         <RFF>             <C506>                 <E1153>ON</E1153>                 <E1154>652744</E1154>             </C506>         </RFF>         <DTM>             <C507>                 <E2005>171</E2005>                 <E2380>20041229</E2380>                 <E2379>102</E2379>             </C507>         </DTM>     </SG1>     <SG3>         <NAD>             <E3035>BY</E3035>             <C082>                 <E3039>4607078289991</E3039>                 <E3055>9</E3055>             </C082>         </NAD>     </SG3>     <SG3>         <NAD>             <E3035>SU</E3035>             <C082>                 <E3039>4607077429992</E3039>                 <E3055>9</E3055>             </C082>         </NAD>     </SG3>     <SG3>         <NAD>             <E3035>DP</E3035>             <C082>                 <E3039>4606038009747</E3039>                 <E3055>9</E3055>             </C082>         </NAD>     </SG3>     <SG26>         <LIN>             <E1082>1</E1082>             <E1229>3</E1229>             <C212>                 <E7140>03312345501003</E7140>                 <E7143>SRV</E7143>             </C212>         </LIN>      <PIA>          <E4347>1</E4347>          <C212>              <E7140>23543245634</E7140>              <E7143>SA</E7143>          </C212>      </PIA>      <PIA>          <E4347>1</E4347>          <C212>              <E7140>657867</E7140>              <E7143>IN</E7143>          </C212>      </PIA>         <QTY>             <C186>                 <E6063>21</E6063>                 <E6060>500</E6060>             </C186>         </QTY>         <QTY>             <C186>                 <E6063>170</E6063>                 <E6060>300</E6060>             </C186>         </QTY>      <SG30>          <PRI>              <C509>                  <E5125>AAA</E5125>                  <E5118>342.00</E5118>              </C509>          </PRI>      </SG30>     </SG26>     <UNS>         <E0081>S</E0081>     </UNS>     <CNT>         <C270>          <E6069>2</E6069>          <E6066>1</E6066>         </C270>     </CNT>     <UNT>         <E0074>15</E0074>         <E0062>MSG127</E0062>     </UNT> </ORDRSP> `; const subst = `><`; // The substituted value will be contained in the result variable const result = str.replace(regex, subst); console.log('Substitution result: ', 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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions