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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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 = '/<slb:ReturnCode>([^<]*?)<\/slb:ReturnCode>[\s\S]*?<slb:Message>([^<]*?)<\/slb:Message>[\s\S]*?<slb:Message>([^<]*?)<\/slb:Message>[\s\S]*?<slb:Message>([^<]*?)<\/slb:Message>[\s\S]*?<slb:Count>([^<]*?)<\/slb:Count>|<slb:SerialNumber>([^<]*?)<\/slb:SerialNumber>[\s\S]*?<slb:Type>([^<]*?)<\/slb:Type>[\s\S]*?<slb:Outlet>([^<]*?)<\/slb:Outlet>[\s\S]*?<slb:Status>([^<]*?)<\/slb:Status>/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:SendCustomerLocationEquipmentActionResponse><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>2.15</slb:Version><slb:Operator>IVR</slb:Operator><slb:TransactionId>d2330147-1564-11eb-8111-005056b21df3</slb:TransactionId><slb:ServerId>OTPRESLBWCF04</slb:ServerId></slb:head><slb:Response><slb:ReturnCode>0000</slb:ReturnCode><slb:Message>ICP26I - ALL EQUIPMENT THIS PAGE HIT</slb:Message><slb:Message>ICP21I - ALL EQUIPMENT HAS BEEN REHIT</slb:Message><slb:Message>ICP28I - REQ ACT ON THIS PAGE PERFORMED</slb:Message></slb:Response><slb:Business><slb:BusinessUnit>802440000360</slb:BusinessUnit></slb:Business><slb:Customer><slb:CustomerId>1101521209580</slb:CustomerId></slb:Customer><slb:Location><slb:LocationId>11322010200009</slb:LocationId></slb:Location><slb:EquipmentList><slb:Count>3</slb:Count><slb:ReturnedCount>3</slb:ReturnedCount><slb:Equipment><slb:SerialNumber>C8C937E6B65C </slb:SerialNumber><slb:Type>MN</slb:Type><slb:TypeDescription>D3 Modem-Arris</slb:TypeDescription><slb:SubType> </slb:SubType><slb:Outlet>A </slb:Outlet><slb:Sequence>00</slb:Sequence><slb:Status>H</slb:Status><slb:StatusDescription>Active</slb:StatusDescription><slb:CurrentLocation>8024400360071309</slb:CurrentLocation><slb:Manufacturer>AR</slb:Manufacturer><slb:Make>ARRIS</slb:Make><slb:Model>DG3270 </slb:Model><slb:ModelDescription>Arris Modem</slb:ModelDescription><slb:Ownership>P</slb:Ownership><slb:OwnershipDescription>PURCHASED </slb:OwnershipDescription><slb:Inventoried>I</slb:Inventoried><slb:SignalType>D</slb:SignalType><slb:ComponentCount>1</slb:ComponentCount><slb:Component><slb:Code>03</slb:Code><slb:CodeDescription> </slb:CodeDescription><slb:Status>H</slb:Status><slb:StatusDescription>Active</slb:StatusDescription><slb:Path>27</slb:Path><slb:Category>03</slb:Category><slb:AddressingMode>1</slb:AddressingMode><slb:Usage><slb:Enabled>Y</slb:Enabled></slb:Usage><slb:ItemCount>4</slb:ItemCount><slb:Item><slb:ServiceIdentifier>000011</slb:ServiceIdentifier><slb:Code>F0090</slb:Code><slb:CodeDescription>Edgew 100</slb:CodeDescription></slb:Item><slb:Item><slb:ServiceIdentifier>000005</slb:ServiceIdentifier><slb:Code>F0089</slb:Code><slb:CodeDescription>Internetbase</slb:CodeDescription></slb:Item><slb:Item><slb:ServiceIdentifier>000010</slb:ServiceIdentifier><slb:Code>O$</slb:Code><slb:CodeDescription>D3 Modem</slb:CodeDescription></slb:Item><slb:Item><slb:ServiceIdentifier>000007</slb:ServiceIdentifier><slb:Code>A0014</slb:Code><slb:CodeDescription>Ineligtocncl</slb:CodeDescription></slb:Item></slb:Component><slb:ReceiptDate>2018-06-28</slb:ReceiptDate><slb:RepairDate>0001-01-01</slb:RepairDate><slb:ShipDate>2018-06-28</slb:ShipDate><slb:VendorDescription>ARRIS </slb:VendorDescription><slb:VendorModel>DG3270 </slb:VendorModel><slb:DOCSISVersion>0</slb:DOCSISVersion><slb:RecordState>P21</slb:RecordState></slb:Equipment><slb:Equipment><slb:SerialNumber>A950527CE7C60H5 </slb:SerialNumber><slb:Type>TV</slb:Type><slb:TypeDescription>Tivo Mi4</slb:TypeDescription><slb:SubType> </slb:SubType><slb:Outlet>B </slb:Outlet><slb:Sequence>00</slb:Sequence><slb:Status>H</slb:Status><slb:StatusDescription>Active</slb:StatusDescription><slb:CurrentLocation>8024400360071309</slb:CurrentLocation><slb:Make>TIVO </slb:Make><slb:Model>MI4 </slb:Model><slb:Ownership>P</slb:Ownership><slb:OwnershipDescription>PURCHASED </slb:OwnershipDescription><slb:Inventoried>I</slb:Inventoried><slb:SignalType>A</slb:SignalType><slb:ComponentCount>1</slb:ComponentCount><slb:Component><slb:Code>01</slb:Code><slb:CodeDescription> </slb:CodeDescription><slb:Status>H</slb:Status><slb:StatusDescription>Active</slb:StatusDescription><slb:Path>27</slb:Path><slb:Category>01</slb:Category><slb:AddressingMode>0</slb:AddressingMode><slb:Usage><slb:Enabled>Y</slb:Enabled></slb:Usage><slb:ItemCount>4</slb:ItemCount><slb:Item><slb:ServiceIdentifier>000012</slb:ServiceIdentifier><slb:Code>OL002</slb:Code><slb:CodeDescription>Dvr</slb:CodeDescription></slb:Item><slb:Item><slb:ServiceIdentifier>000004</slb:ServiceIdentifier><slb:Code>BL051</slb:Code><slb:CodeDescription>TV Ch Exch</slb:CodeDescription></slb:Item><slb:Item><slb:ServiceIdentifier>000006</slb:ServiceIdentifier><slb:Code>OL092</slb:Code><slb:CodeDescription>Essen+ Base</slb:CodeDescription></slb:Item><slb:Item><slb:ServiceIdentifier>000007</slb:ServiceIdentifier><slb:Code>A0014</slb:Code><slb:CodeDescription>Ineligtocncl</slb:CodeDescription></slb:Item></slb:Component><slb:ReceiptDate>2020-06-10</slb:ReceiptDate><slb:RepairDate>0001-01-01</slb:RepairDate><slb:ShipDate>2020-06-10</slb:ShipDate><slb:OffPremiseEquipment><slb:UnitNumber>ION NEVER ATT</slb:UnitNumber><slb:Port><slb:Number> </slb:Number></slb:Port></slb:OffPremiseEquipment><slb:RecordState>NOC</slb:RecordState></slb:Equipment><slb:Equipment><slb:SerialNumber>DBD1BDA5C3DA </slb:SerialNumber><slb:Type>MN</slb:Type><slb:TypeDescription>D3 Modem-Arris</slb:TypeDescription><slb:SubType> </slb:SubType><slb:Outlet>C </slb:Outlet><slb:Sequence>00</slb:Sequence><slb:Status>D</slb:Status><slb:StatusDescription>Disabled</slb:StatusDescription><slb:CurrentLocation>8024400360071309</slb:CurrentLocation><slb:Manufacturer>AR</slb:Manufacturer><slb:Make>MOTLA</slb:Make><slb:Model>DG3270 </slb:Model><slb:ModelDescription>Arris Modem</slb:ModelDescription><slb:Ownership>R</slb:Ownership><slb:OwnershipDescription>RENTAL/LEASE </slb:OwnershipDescription><slb:Inventoried>I</slb:Inventoried><slb:SignalType>D</slb:SignalType><slb:ComponentCount>1</slb:ComponentCount><slb:Component><slb:Code>03</slb:Code><slb:CodeDescription> </slb:CodeDescription><slb:Status>D</slb:Status><slb:StatusDescription>Disabled</slb:StatusDescription><slb:Path>27</slb:Path><slb:Category>03</slb:Category><slb:AddressingMode>1</slb:AddressingMode><slb:Usage><slb:Enabled>Y</slb:Enabled></slb:Usage><slb:ItemCount>0</slb:ItemCount></slb:Component><slb:ReceiptDate>2018-04-02</slb:ReceiptDate><slb:RepairDate>0001-01-01</slb:RepairDate><slb:ShipDate>2018-04-02</slb:ShipDate><slb:VendorDescription>ARRIS </slb:VendorDescription><slb:VendorModel>DG3270 </slb:VendorModel><slb:DOCSISVersion>0</slb:DOCSISVersion><slb:RecordState>NOC</slb:RecordState></slb:Equipment></slb:EquipmentList></slb:SendCustomerLocationEquipmentActionResponse></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