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

/
/
ims

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"((<.*?):Envelope.*Envelope>)"; string input = @"31-10-2014 00:12:12,075 [INFO] REQUEST: <?xml version=""1.0"" encoding=""utf-8""?><SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:SOAP-ENC=""http://schemas.xmlsoap.org/soap/encoding/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:ns2=""urn:ZEKTransactionService"" xmlns:ns1=""http://zeksoap.xml.prechku.sys:7001/dvzek/services/ZEKTransactionService"" xmlns:ns3=""http://impl.zkb.appl.ch""><SOAP-ENV:Body SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""><ns1:closeLeasingMietvertrag><identityDescriptor xsi:type=""ns2:IdentityDescriptor""><clientUserId xsi:type=""xsd:string"">EXPLOIT</clientUserId><name xsi:type=""xsd:string"">RCISoapUser</name><password xsi:type=""xsd:string"">ziucx+okpb</password></identityDescriptor><requestEntities xsi:type=""SOAP-ENC:Array"" SOAP-ENC:arrayType=""ns2:RequestEntity[1]""><item xsi:type=""ns2:RequestEntity""><addressDescription xsi:type=""ns2:AddressDescription""><birthdate xsi:type=""xsd:string"">1961-03-13</birthdate><city xsi:type=""xsd:string"">Balsthal</city><country xsi:type=""xsd:string"">CHE</country><datumWohnhaftSeit xsi:type=""xsd:string"">1990-04-01</datumWohnhaftSeit><firstname xsi:type=""xsd:string"">Mina</firstname><housenumber xsi:type=""xsd:string"">.</housenumber><legalForm xsi:type=""xsd:int"">1</legalForm><name xsi:type=""xsd:string"">Bilalli</name><nationality xsi:type=""xsd:string"">XKO</nationality><sex xsi:type=""xsd:int"">1</sex><street xsi:type=""xsd:string"">Guntenfluhweg 14</street><zip xsi:type=""xsd:string"">4710</zip><zivilstandscode xsi:type=""xsd:int"">1</zivilstandscode></addressDescription><debtorRole xsi:type=""xsd:int"">0</debtorRole><forceNewAddress xsi:type=""xsd:int"">0</forceNewAddress><previousReturnCode xsi:type=""xsd:int"">0</previousReturnCode><refno xsi:type=""xsd:int"">1</refno></item></requestEntities><leasingMietvertrag xsi:type=""ns2:LeasingMietvertragDescription""><anzahlMonatlicheRaten xsi:type=""xsd:int"">0</anzahlMonatlicheRaten><anzahlung xsi:type=""xsd:int"">0</anzahlung><bonitaetsCodeIKO xsi:type=""xsd:int"">4</bonitaetsCodeIKO><bonitaetsCodeZEK xsi:type=""xsd:int"">5</bonitaetsCodeZEK><datumBonitaetIKO xsi:type=""xsd:string"">2014-10-30</datumBonitaetIKO><datumBonitaetZEK xsi:type=""xsd:string"">2014-10-30</datumBonitaetZEK><debtorRole xsi:type=""xsd:int"">0</debtorRole><ersteGrosseRate xsi:type=""xsd:int"">0</ersteGrosseRate><filiale xsi:type=""xsd:int"">0</filiale><grosseSchlussrate xsi:type=""xsd:int"">0</grosseSchlussrate><herkunft xsi:type=""xsd:int"">0</herkunft><kennzeichen xsi:type=""xsd:int"">0</kennzeichen><kreditBetrag xsi:type=""xsd:float"">0</kreditBetrag><kreditVertragID xsi:type=""xsd:string"">142051011553</kreditVertragID><monatsrate xsi:type=""xsd:float"">0</monatsrate><restwert xsi:type=""xsd:int"">0</restwert><sicherstellungsCode xsi:type=""xsd:int"">0</sicherstellungsCode><theoRestSaldo xsi:type=""xsd:float"">0</theoRestSaldo><vertragsStatus xsi:type=""xsd:int"">0</vertragsStatus></leasingMietvertrag></ns1:closeLeasingMietvertrag></SOAP-ENV:Body></SOAP-ENV:Envelope> | Thread:http-7001-Processor23"; RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline; Match m = Regex.Match(input, pattern, options); Console.WriteLine("'{0}' found at index {1}", m.Value, m.Index); } }

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx