Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

Test String

Code Generator

Generated Code

$re = '/<slb:ReturnCode>(?<ReturnCode>.*?)<\/slb:ReturnCode>.*?(?:<slb:Message>(?<FailureMessage>.*?)<\/slb:Message>|<slb:SearchResultsCount>(?<Count>\d)<\/slb:SearchResultsCount>).*?<slb:CustomerId>(?<CustomerID>.*?)<\/slb:CustomerId>.*?<slb:AccountId>(?<AccoundId>.*?)<\/slb:AccountId>.*?<slb:LocationId>(?<LocationId>.*?)<\/slb:LocationId>/m'; $str = '<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:slb="http://www.csgsystems.com/slbos"><soapenv:Header /><soapenv:Body><slb:RetrieveAccountResponse><slb:head><slb:Client>ElnkFive9IOT</slb:Client><slb:RoutingArea>8024</slb:RoutingArea><slb:Region>QAHA</slb:Region><slb:Source>IVR</slb:Source><slb:Destination>CCS</slb:Destination><slb:Version>17.4</slb:Version><slb:TransactionId>72ccf13c-1534-11eb-8111-005056b21df3</slb:TransactionId><slb:ServerId>OTPRESLBWCF04</slb:ServerId></slb:head><slb:Response><slb:ReturnCode>0000</slb:ReturnCode></slb:Response><slb:SearchResultsCount>1</slb:SearchResultsCount><slb:SearchResults><slb:Region>QAHA</slb:Region><slb:Business><slb:BusinessUnit>802440000360</slb:BusinessUnit></slb:Business><slb:Customer><slb:CustomerId>1101521209580</slb:CustomerId></slb:Customer><slb:Account><slb:AccountId>8024400360071309</slb:AccountId><slb:Classification> </slb:Classification><slb:Type>RES</slb:Type><slb:ConnectStatus> </slb:ConnectStatus><slb:Name><slb:Salutation>U</slb:Salutation><slb:First>TEST2</slb:First><slb:Last>FIVE9SWAP</slb:Last></slb:Name><slb:Phone><slb:Home>9026852256</slb:Home></slb:Phone><slb:LineOfBusinessCount>5</slb:LineOfBusinessCount><slb:LineOfBusiness><slb:Type>C</slb:Type><slb:TypeDescription>VIDEO </slb:TypeDescription><slb:Status>A</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>I</slb:Type><slb:TypeDescription>HSD </slb:TypeDescription><slb:Status>A</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>T</slb:Type><slb:TypeDescription>TELEPHONY</slb:TypeDescription><slb:Status>N</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>Y</slb:Type><slb:TypeDescription>WIRELESS </slb:TypeDescription><slb:Status>N</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>Z</slb:Type><slb:TypeDescription>SECURITY </slb:TypeDescription><slb:Status>N</slb:Status></slb:LineOfBusiness><slb:Balance><slb:Current>155.14</slb:Current><slb:Projected>155.14</slb:Projected><slb:Statement>155.14</slb:Statement><slb:Highest>155.00</slb:Highest></slb:Balance><slb:PPVCreditLimit>250.00</slb:PPVCreditLimit><slb:Payment><slb:SubType> </slb:SubType><slb:SubTypeStatus> </slb:SubTypeStatus><slb:History>0 </slb:History><slb:LastDate>0001-01-01</slb:LastDate><slb:LastAmount>0.00</slb:LastAmount><slb:FutureDated>N</slb:FutureDated></slb:Payment><slb:BillTo><slb:Name><slb:Salutation>U</slb:Salutation><slb:First>TEST2</slb:First><slb:Last>FIVE9SWAP</slb:Last></slb:Name><slb:StatementNameFormat>2</slb:StatementNameFormat><slb:Address><slb:Line1>123 SEAN ST</slb:Line1><slb:City>HALIFAX</slb:City><slb:State>NS</slb:State><slb:PostalCode>B3M0A2</slb:PostalCode><slb:ForceIndicator>1</slb:ForceIndicator><slb:Country>CAN</slb:Country></slb:Address><slb:AddressInheritanceIndicator>Y</slb:AddressInheritanceIndicator></slb:BillTo><slb:Billing><slb:CycleDay>22</slb:CycleDay><slb:FromDate>2020-10-22</slb:FromDate><slb:ThruDate>2020-11-21</slb:ThruDate><slb:Frequency>01</slb:Frequency><slb:TaxGroup>99</slb:TaxGroup><slb:DemandStatement>N</slb:DemandStatement><slb:StatementHold>N</slb:StatementHold><slb:EBPP>N</slb:EBPP><slb:Electronic>N</slb:Electronic><slb:ElectronicOutsourced>N</slb:ElectronicOutsourced><slb:Hardcopy>Y</slb:Hardcopy></slb:Billing><slb:Identification><slb:TaxIdentifier>XXXXXXXXX</slb:TaxIdentifier><slb:TaxType>X</slb:TaxType><slb:PIN>00000</slb:PIN></slb:Identification><slb:Delinquency><slb:Status> </slb:Status><slb:ChargeOff><slb:Reason slb:Index="1"><slb:Code>00</slb:Code><slb:Description>Misappld Pymnt</slb:Description></slb:Reason><slb:Amount>0.00</slb:Amount></slb:ChargeOff><slb:DunningGroup>030</slb:DunningGroup></slb:Delinquency><slb:MonetaryStatus> </slb:MonetaryStatus><slb:SalesRepresentative>0</slb:SalesRepresentative><slb:ConnectDate>2020-10-22</slb:ConnectDate><slb:LastMonetaryType>S</slb:LastMonetaryType><slb:LastMonetaryDate>2020-10-22</slb:LastMonetaryDate><slb:LastNonMonetaryDate>2020-10-22</slb:LastNonMonetaryDate><slb:AutoPackageIndicator>P</slb:AutoPackageIndicator><slb:RestrictTroubleCall>N</slb:RestrictTroubleCall><slb:RestrictPPV>N</slb:RestrictPPV><slb:CustomField slb:Index="2"><slb:Name>RETIREE ID </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="3"><slb:Name>COM TEST1 </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="4"><slb:Name>COMM CLASS </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="5"><slb:Name>ARMSTRONG ACCT</slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="6"><slb:Name>NO COLLECTIONS</slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="7"><slb:Name>COLLECT LETTER</slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="8"><slb:Name>CONTRACT (ER) </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="9"><slb:Name>BWOS # </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="10"><slb:Name>BANKRUPTCY </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="11"><slb:Name>COLLECTIONS </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="12"><slb:Name>PAY ARRANGEMEN</slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="13"><slb:Name>MIND ACCT # </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="14"><slb:Name>AM COLLECTOR #</slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="15"><slb:Name>LOW USAGE </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:CustomField slb:Index="16"><slb:Name>LEGACY ACCT# </slb:Name><slb:Value> </slb:Value></slb:CustomField><slb:Audit><slb:Creation><slb:Date>2020-10-22</slb:Date></slb:Creation></slb:Audit></slb:Account><slb:Location><slb:LocationId>11322010200009</slb:LocationId><slb:Type>AA</slb:Type><slb:TypeDescription>Residence</slb:TypeDescription><slb:Address><slb:Line1>123 SEAN ST</slb:Line1><slb:City>HALIFAX</slb:City><slb:State>NS</slb:State><slb:PostalCode>113220102</slb:PostalCode></slb:Address><slb:LineOfBusinessCount>4</slb:LineOfBusinessCount><slb:LineOfBusiness><slb:Type>C</slb:Type><slb:TypeDescription>VIDEO </slb:TypeDescription><slb:Status>A</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>I</slb:Type><slb:TypeDescription>HSD </slb:TypeDescription><slb:Status>A</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>T</slb:Type><slb:TypeDescription>VOICE </slb:TypeDescription><slb:Status>A</slb:Status></slb:LineOfBusiness><slb:LineOfBusiness><slb:Type>Z</slb:Type><slb:TypeDescription>SECURITY </slb:TypeDescription><slb:Status>N</slb:Status></slb:LineOfBusiness><slb:Drop><slb:Tag slb:Index="1"><slb:Identifier>SEAN</slb:Identifier></slb:Tag></slb:Drop></slb:Location></slb:SearchResults></slb:RetrieveAccountResponse></soapenv:Body></soapenv:Envelope>'; 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