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

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"Gesamtenergie.*\n.*\n*\s*\s(\d*)"; string input = @"<!DOCtype HTML PUBLIC ""-//W3C//Dtd HTML 4.0 Transitional//EN""> <html> <head> <meta HTTP-EQUIV=""Content-Type"" CONTENT=""text/html; charset=ISO-8859-1""> <meta name=""Generator"" CONTENT=""ChrisB""> <title>PV Webserver</title> </head> <body nof=""(MB=(DefaultMasterborder, 65, 60, 150, 10), L=(HomeLayout, 700, 600))"" bgcolor=""#EAF7F7"" text=""#000000"" link=""#0033CC"" vlink=""#990099"" alink=""#FF0000"" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0> <form method=""post"" action=""> <table cellspacing=""0"" cellpadding=""0"" width=""770"" nof=""ly""> <tr><td height=""5""></td></tr> <tr><td width=""190"" height=""55""></td> <td width=""400""> <font face=""Arial,Helvetica,Geneva,Sans-serif,sans-serif"" size=""+3""> PIKO 5.5 <br><font size=""+1""> S_Power (220) </font> </font> </td> <td><img alt=""Logo"" height=""42"" width=""130"" src=""KSE.gif""></td> </tr> </table> <font face=""Arial,Helvetica,Geneva,Sans-serif,sans-serif""> <table Border=""0"" width=""100%""><tr> <td width=""150""></td> <td> <hr> </td> </tr></table> <table cellspacing=""0"" cellpadding=""0"" width=""770""> <tr><td></td></tr> <tr> <td width=""190""></td> <td colspan=""2""> <b>AC-Leistung</b></td> <td>&nbsp</td> <td> <b>Energie</b></td></tr> <tr><td height=""10""></td></tr> <tr> <td width=""190""></td> <td width=""100""> aktuell</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> x x x&nbsp</td> <td width=""140"">&nbsp W</td> <td width=""100""> Gesamtenergie</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> 33763</td> <td width=""50"">&nbsp kWh</td> <td>&nbsp</td></tr> <tr height=""2""><td></td></tr> <tr> <td width=""190""></td> <td width=""100""> &nbsp</td> <td width=""70"" align=""right""> &nbsp</td> <td width=""140"">&nbsp</td> <td width=""100""> Tagesenergie</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> 22.85</td> <td width=""50"">&nbsp kWh</td> <td>&nbsp</td></tr> <tr height=""5""><td></td></tr> <tr> <td width=""190""></td> <td width=""100""> Status</td> <td colspan=""4""> Aus</td> <td>&nbsp</td></tr> <tr height=""8""><td></td></tr> <tr><td colspan=""7""> <table align=""top"" width=""100%""><tr> <td width=""182""></td> <td><hr size=""1""></font></td></tr> <tr><td height=""5""></td></tr></table> </td></tr> <tr> <td width=""190""></td> <td colspan=""2""> <b>PV-Generator</b></td> <td width=""140"">&nbsp</td> <td colspan=""2""> <b>Ausgangsleistung</b></td> <td width=""30"">&nbsp</td> <td>&nbsp</td></tr> <tr><td height=""10""></td></tr> <tr> <td width=""190""></td> <td width=""100""> <u>String 1</u></td> <td width=""70"">&nbsp</td> <td width=""140"">&nbsp</td> <td width=""95""> <u>L1</u></td> <td width=""70"">&nbsp</td> <td width=""30"">&nbsp</td> <td>&nbsp</td></tr> <tr> <td width=""190""></td> <td width=""100""> Spannung</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> x x x&nbsp</td> <td width=""140"">&nbsp V</td> <td width=""100""> Spannung</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> x x x&nbsp</td> <td width=""30"">&nbsp V</td> <td>&nbsp</td></tr> <tr height=""2""><td></td></tr> <tr valign=""top"" align=""left""> <td width=""190"">&nbsp</td> <td width=""100""> Strom</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> x x x&nbsp</td> <td width=""140"">&nbsp A</td> <td width=""100""> Leistung</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> x x x&nbsp</td> <td width=""30"">&nbsp W</td> <td>&nbsp</td></tr> <tr height=""22""><td></td></tr> <tr> <td width=""190""></td> <td width=""100""> <u>String 2</u></td> <td width=""70"">&nbsp</td> <td width=""140"">&nbsp</td> <td width=""100""> <u>L2</u></td> <td width=""70"">&nbsp</td> <td width=""30"">&nbsp</td> <td>&nbsp</td></tr> <tr> <td width=""190""></td> <td width=""100""> Spannung</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> x x x&nbsp</td> <td width=""140"">&nbsp V</td> <td width=""100""> Spannung</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> x x x&nbsp</td> <td width=""30"">&nbsp V</td> <td>&nbsp</td></tr> <tr height=""2""><td></td></tr> <tr valign=""top"" align=""left""> <td width=""190"">&nbsp</td> <td width=""100""> Strom</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> x x x&nbsp</td> <td width=""140"">&nbsp A</td> <td width=""100""> Leistung</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> x x x&nbsp</td> <td width=""30"">&nbsp W</td> <td>&nbsp</td></tr> <tr height=""22""><td></td></tr> <tr> <td width=""190""></td> <td width=""100""> <u>String 3</u></td> <td width=""70"">&nbsp</td> <td width=""140"">&nbsp</td> <td width=""100""> <u>L3</u></td> <td width=""70"">&nbsp</td> <td width=""30"">&nbsp</td> <td>&nbsp</td></tr> <tr> <td width=""190""></td> <td width=""100""> Spannung</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> x x x&nbsp</td> <td width=""140"">&nbsp V</td> <td width=""95""> Spannung</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> x x x&nbsp</td> <td width=""30"">&nbsp V</td> <td>&nbsp</td></tr> <tr height=""2""><td></td></tr> <tr valign=""top"" align=""left""> <td width=""190"">&nbsp</td> <td width=""95""> Strom</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> x x x&nbsp</td> <td width=""140"">&nbsp A</td> <td width=""95""> Leistung</td> <td width=""70"" align=""right"" bgcolor=""#FFFFFF""> x x x&nbsp</td> <td width=""30"">&nbsp W</td> <td>&nbsp</td></tr> <tr><td height=""15""></td></tr> <tr><td colspan=""7""> <table align=""top"" width=""100%""> <tr><td width=""182""></td> <td><hr size=""1""></font></td> </tr><tr><td height=""5""></td></tr></table> </td></tr></table> <table cellspacing=""0"" cellpadding=""0"" width=""770""> <tr><td width=""190""></td> <td><font face=""Arial,Helvetica,Geneva,Sans-serif""> <b>RS485 Kommunikation</b></td></tr> <tr><td height=""8""></td></tr> <tr><td width=""190""></td> <td><font face=""Arial,Helvetica,Geneva,Sans-serif""> Wechselrichter&nbsp <input type=""Text"" name=""edWrNr"" value=""220"" size=""3"" maxlength=""3""> <input type=""submit"" value=""Anzeigen/Aktualisieren""> </td></tr><tr><td height=""10""></td></tr> </table> </td></tr></table></font> <hr> <table cellspacing=""0"" cellpadding=""0"" width=""770""> <tr><td height=""5""></td></tr> <tr><td width=""190""></td> <td width=""330""> <font face=""Arial,Helvetica,Geneva,Sans-serif,sans-serif""> <a href=""LogDaten.dat"">Historie</a> &nbsp &nbsp &nbsp <a href=""Info.fhtml"">Infoseite</a></font></td> <td align=""right""> <font face=""Arial,Helvetica,Geneva,Sans-serif,sans-serif""> <a href=""Solar2.fhtml"">Einstellungen</a></font></td> <td width=""50""></td> </tr></table></font> </form> </body> </html> "; foreach (Match m in Regex.Matches(input, pattern)) { 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