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

/
/
sgm

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(<ptS[a-zA-Z]*Text[a-zA-Z0-9\/=\+\n\t\r\0 ""]+>)([a-zA-Z0-9\/=+\n\t\r\0 &#;\-\.\(\),:£]+)(<\/ptS[a-zA-Z]*Text[a-zA-Z0-9\/=\+\n\t\r\0 ""]*>)"; string input = @"<CDBText id=""(0:0-51181)""> <dwRefTextOrdner>5622</dwRefTextOrdner> <dwRefMitarbeiter>0</dwRefMitarbeiter> <ptSName code=""None"" lang=""en"">OWN_Text 15</ptSName> <dBreite>21</dBreite> <dHoehe>29.699999999999999</dHoehe> <dOben>2</dOben> <dUnten>2</dUnten> <dLinks>2</dLinks> <dRechts>2</dRechts> <cHochQuerformat>0x00</cHochQuerformat> <cPapierSchacht>0</cPapierSchacht> <cPapierSchachtErsteSeite>0</cPapierSchachtErsteSeite> <ptSDruckername code=""None"" lang=""en""></ptSDruckername> <ptDErstellungsdatum>Thu 04.Sep 2008</ptDErstellungsdatum> <ptDSpeicherungsdatum>Thu 04.Sep 2008</ptDSpeicherungsdatum> <ptTSpeicherungszeit>10:10:10 am</ptTSpeicherungszeit> <nVersion>3</nVersion> <ptSTitel code=""None"" lang=""en""></ptSTitel> <ptSThema code=""None"" lang=""en""></ptSThema> <ptSAutor code=""None"" lang=""en"">ld</ptSAutor> <ptSKommentar code=""None"" lang=""en""></ptSKommentar> <cGeschuetzt>0x00</cGeschuetzt> <cDBTextDaten><xref refid=""(0:0-51182)""/></cDBTextDaten> </CDBText> <CDBTextDaten id=""(0:0-51182)""> <ptBKopfzeileText len=""0"" crc=""0""> </ptBKopfzeileText> <ptSKopfzeileText code=""None"" lang=""en""></ptSKopfzeileText> <ptBKopfzeileFormat len=""0"" crc=""0""> </ptBKopfzeileFormat> <ptBFusszeileText len=""0"" crc=""0""> </ptBFusszeileText> <ptSFusszeileText code=""None"" lang=""en""></ptSFusszeileText> <ptBFusszeileFormat len=""0"" crc=""0""> </ptBFusszeileFormat> <ptBMitteText len=""1031"" crc=""3139242066""> 8PHw/1BLAwQUAAAACABFUSQ5KkncyMoCAADTBAAAKwBwAERPQ1VNRX4xL0NBVENM SX4xL0xPQ0FMU34xL1RlbXAvMi9ibG8zMC50bXBTRFsApAAAAAAIALXyphxjZGBp EGFgYDBggAAfIGZkBTNZRYFE/LvcS4ufyjZ5Wa+KSmHBLcfIxMDAxBDBwAyWlmD4 zyjPABIDqVUAEgpgtghEnBEiLgSmVCBieOwEAFVUDQAH8qW/SPKlv0jypb9IbVPd TtswFO7dtEp9h3MJoi0dGruAq6pkUIlS1HYgLt3k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AAAA= </ptBMitteText> <ptSMitteText code=""None"" lang=""en"">CONSENT FORM &#59549; &#59549; &#59543;&#59543;&#59543;&#59543;&#59549; &#59543;&#59543;&#59543;&#59543;&#59549; &#59543;&#59543;&#59543;&#59543;&#59549; &#59549; &#59543;&#59543;&#59549; We strongly recommend that all pets are up-to-date with vaccinations before admission.&#59549; Please ask if you are unsure whether your dog or cat is fully protected.&#59549; &#59549; RELEVANT MEDICAL HISTORY see records (gosforth)&#59549; &#59549; &#59549; PROCEDURE General anaesthetic, scale and polish + extraction of broken tooth, +/- any other extractions&#59549; &#59549; &#59549; &#59543;&#59543;&#59549; &#59543;&#59543;&#59549; &#59543;&#59543;&#59549; &#59549; I give my permission for the above procedure and understand that all such procedures carry a small element of risk.&#59549; I understand that Croft Vets use the best opioid pain control available and consent to the use of this safe and effective human drug in my pet..&#59549; &#59549; &#59543;&#59543;&#59543;&#59543;&#59549; &#59549; We recommend that all patients undergoing major surgery, especially older pets,have a blood test just before administration of a general anaesthetic.&#59549; &#59549; I do / do not require a pre-operative blood screen for my pet Small animals (patient file):Name;10650;10650;0;4;&#59549; &#59549; AGREEMENT TO PAY&#59549; ESTIMATE: £200 - 225&#59549; &#59549; It is our policy to provide clients with an accurate fee estimate.&#59549; However, the very nature of veterinary medicine and surgery makes it impossible to predict costs exactly.&#59549; I agree to pay all fees on collection of my pet.&#59549; &#59543;&#59543;&#59543;&#59543;&#59543;&#59543;&#59543;&#59549; &#59549; Signed:&#59549; &#59543;&#59543;&#59543;&#59543;&#59549; </ptSMitteText> <ptBMitteFormat len=""3251"" crc=""1808381608""> 8PHw/1BLAwQUAAAACABFUSQ5oClCBnYLAADi2AAAKwBwAERPQ1VNRX4xL0NBVENM SX4xL0xPQ0FMU34xL1RlbXAvMi9ibG8zMi50bXBTRFsApAAAAAAIALXyphxjZGBp EGFgYDBggAAfIGZkBTNZRYFE/LvcS4ufyjZ5Wa+KSmHBLcfIxMDAxBDBwAyWlmD4 zyjPABIDqVUAEgpgtghE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+79SC9Rl2TH7D4vph159wGbr2WAH2 YuC0TJc+aGXsNaYz22xIr+Y2vFyd5Jj8hq71db/Ape4pPFcrk+wJ8541fr/buPyF KfIXptpfbk29AL+oNb4X29jdwqWfXUt5fCFJOs/pigK8xVvNPD/PSUNKzVPdq6eN 2zlpM/TVY9zqPmao2z7v860/43bD+bZymR56o0hZw1mXvH9mavOfHjpcmoc1nGw7 zG6Xr7Ong30b0dN6qNvl9qVexVlKP59K8QPFDxQ/AMUPZuIHlbPaVFFljlZxRhSm PVyd3ejWnsI8kCjRLigNf9fwhYrkDY7NaT0uyNOvqLYHQoMpobmsmKBJ0CRoEjQJ movhV1RvK+ypX5nIHkHHGv3jI8g7NB8oDT+Zgvb6hR+xxxWWvDccilnDX83QTYl9 kC/z4aaw38o9GAwFGlr7+6VQKOWiyqtWgj5Bn6BP0Cfom4G+OiMV26GA/epA4uiv hozcLKpU14ecWJWdM/AQ8s5UXtMbkGy4fV51G2u3Gurm802PI4o/Ub8mX0P5/86H Z8IOyNYApR69/wP5JOSTkE9CPgmQT8JrA2Clq+VoIGJcwdgeA8bSw+fO8jzAh8Pa 1H+sIjoRnYhORCeiE9+1qbE9/RilYmtTNVOf84yeY/ub44VLIdi6Ob6SqH/cVpSn gd32Qan/uDQg9k2kDqJaSghThCnCFGGKMMVrYJdZaU43sqvO8lvxTWWLdAA3menX vv8PUEsBAhcLFAAAAAgARVEkOaApQgZ2CwAA4tgAACsAEQAAAAAAAAAgALaBAAAA AERPQ1VNRX4xL0NBVENMSX4xL0xPQ0FMU34xL1RlbXAvMi9ibG8zMi50bXBTRAQA pAAAAFVUBQAH8qW/SFBLBQYAAAAAAQABAGoAAAAvDAAAAAA= </ptBMitteFormat> </CDBTextDaten> "; RegexOptions options = RegexOptions.Singleline | RegexOptions.Multiline; foreach (Match m in Regex.Matches(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