Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(?:(?!<(?:field|exclGroup)(?!\w)(?>""[\S\s]*?""|'[\S\s]*?'|(?:(?!\/>)[^>])?)+>)[\S\s])*(?><(field|exclGroup)(?=(?:[^>""']|""[^""]*""|'[^']*')*?\sname\s*=\s*(?:(['""])([\S\s]*?)\2))\s+(?>""[\S\s]*?""|'[\S\s]*?'|(?:(?!\/>)[^>])?)+>)(?:(?&core)|)<\/\1\s*>(?:(?!<(?:field|exclGroup)(?!\w)(?>""[\S\s]*?""|'[\S\s]*?'|(?:(?!\/>)[^>])?)+>)[\S\s])*(?(DEFINE)(?<core>(?>(?><([\w:]+)(?>""[\S\s]*?""|'[\S\s]*?'|(?:(?!\/>)[^>])?)+>)(?:(?&core)|)<\/\5\s*>|(?!<\/[\w:]+\s*>)(?>[\S\s]))+))"; string substitution = @"VALUES (12345,""$3"",""/Tx"", "", ""N"", ""Y""),\r\n"; string input = @"<field xmlns=""http://www.xfa.org/schema/xfa-template/2.8/"" y=""0in"" x=""0.343mm"" w=""8.881pt"" h=""9.108pt"" name=""detcon_recreation_only""> <ui> <checkButton size=""8.881pt""> <border> <edge stroke=""lowered""/> <fill/> </border> </checkButton> </ui> <font size=""0pt"" typeface=""Adobe Pi Std""/> <para vAlign=""middle""/> <value> <text>0</text> </value> <items> <text>1</text> <text>0</text> <text/> </items> </field> <field xmlns=""http://www.xfa.org/schema/xfa-template/2.8/"" name=""detcon_special_housing"" y=""5.393mm"" w=""27.94mm"" h=""4.134mm"" x=""0.343mm""> <ui> <choiceList> <border> <edge stroke=""lowered""/> </border> <margin/> </choiceList> </ui> <font typeface=""Arial Narrow"" size=""6pt""/> <margin topInset=""0mm"" bottomInset=""0mm"" leftInset=""0mm"" rightInset=""0mm""/> <para vAlign=""middle""/> <value> <text>NA</text> </value> <items> <text>Not Applicable</text> <text>Hotel Component</text> </items> <items save=""1"" presence=""hidden""> <text>NA</text> <text>HC</text> </items> </field> <exclGroup xmlns=""http://www.xfa.org/schema/xfa-template/2.8/"" name=""detcon_photo_taken"" x=""0in"" y=""0in""> <?templateDesigner itemValuesSpecified 1?> <field w=""12.446mm"" h=""3.825mm"" name=""lb_yes""> <ui> <checkButton size=""1.7639mm"" shape=""round""> <border> <?templateDesigner StyleID apcb1?> <edge/> <fill/> </border> </checkButton> </ui> <font typeface=""Myriad Pro""/> <margin leftInset=""1mm"" rightInset=""1mm""/> <para vAlign=""middle""/> <caption placement=""right"" reserve=""7.698mm""> <para vAlign=""middle"" spaceAbove=""0pt"" spaceBelow=""0pt"" textIndent=""0pt"" marginLeft=""0pt"" marginRight=""0pt""/> <font size=""8pt"" typeface=""Arial Narrow"" baselineShift=""0pt""/> <value> <text>YES</text> </value> </caption> <value> <text xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:nil=""true""/> </value> <items> <text>1</text> </items> </field> <field w=""28.702mm"" h=""3.825mm"" name=""lb_no"" x=""13.233mm""> <ui> <checkButton size=""1.7639mm"" shape=""round""> <border> <?templateDesigner StyleID apcb1?> <edge/> <fill/> </border> </checkButton> </ui> <font typeface=""Myriad Pro""/> <margin leftInset=""1mm"" rightInset=""1mm""/> <para vAlign=""middle""/> <caption placement=""right"" reserve=""23.954mm""> <para vAlign=""middle"" spaceAbove=""0pt"" spaceBelow=""0pt"" textIndent=""0pt"" marginLeft=""0pt"" marginRight=""0pt""/> <font size=""8pt"" typeface=""Arial Narrow"" baselineShift=""0pt""/> <value> <text>NO (see comments)</text> </value> </caption> <value> <text xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:nil=""true""/> </value> <items> <text>0</text> </items> </field> <border> <edge presence=""hidden""/> </border> <?templateDesigner expand 1?></exclGroup>"; Regex regex = new Regex(pattern); string result = regex.Replace(input, substitution); } }

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