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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "Gesamtenergie.*\\n.*\\n*\\s*\\s(\\d*)"; final String string = "<!DOCtype HTML PUBLIC \"-//W3C//Dtd HTML 4.0 Transitional//EN\">\n" + "<html>\n" + "<head>\n" + "<meta HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=ISO-8859-1\">\n" + "<meta name=\"Generator\" CONTENT=\"ChrisB\">\n" + "<title>PV Webserver</title>\n" + "</head>\n" + "<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>\n" + "<form method=\"post\" action=\"\">\n" + "<table cellspacing=\"0\" cellpadding=\"0\" width=\"770\" nof=\"ly\">\n" + "<tr><td height=\"5\"></td></tr>\n" + "<tr><td width=\"190\" height=\"55\"></td>\n" + "<td width=\"400\">\n" + " <font face=\"Arial,Helvetica,Geneva,Sans-serif,sans-serif\" size=\"+3\">\n" + " PIKO 5.5\n" + "<br><font size=\"+1\"> \n" + " S_Power (220)\n" + "</font>\n" + "</font>\n" + "</td>\n" + "<td><img alt=\"Logo\" height=\"42\" width=\"130\" src=\"KSE.gif\"></td>\n" + "</tr>\n" + "</table>\n\n" + "<font face=\"Arial,Helvetica,Geneva,Sans-serif,sans-serif\">\n" + "<table Border=\"0\" width=\"100%\"><tr>\n" + "<td width=\"150\"></td>\n" + "<td> <hr> </td>\n" + "</tr></table>\n" + "<table cellspacing=\"0\" cellpadding=\"0\" width=\"770\">\n" + "<tr><td></td></tr>\n" + "<tr>\n" + "<td width=\"190\"></td>\n" + "<td colspan=\"2\">\n" + " <b>AC-Leistung</b></td>\n" + "<td>&nbsp</td>\n" + "<td>\n" + " <b>Energie</b></td></tr>\n" + "<tr><td height=\"10\"></td></tr>\n\n" + "<tr>\n" + "<td width=\"190\"></td>\n" + "<td width=\"100\">\n" + " aktuell</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " x x x&nbsp</td>\n" + "<td width=\"140\">&nbsp W</td>\n" + "<td width=\"100\">\n" + " Gesamtenergie</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " 33763</td>\n" + "<td width=\"50\">&nbsp kWh</td>\n" + "<td>&nbsp</td></tr>\n" + "<tr height=\"2\"><td></td></tr>\n" + "<tr>\n" + "<td width=\"190\"></td>\n" + "<td width=\"100\">\n" + " &nbsp</td>\n" + "<td width=\"70\" align=\"right\">\n" + " &nbsp</td>\n" + "<td width=\"140\">&nbsp</td>\n" + "<td width=\"100\">\n" + " Tagesenergie</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " 22.85</td>\n" + "<td width=\"50\">&nbsp kWh</td>\n" + "<td>&nbsp</td></tr>\n" + "<tr height=\"5\"><td></td></tr>\n" + "<tr>\n" + "<td width=\"190\"></td>\n" + "<td width=\"100\">\n" + " Status</td>\n" + "<td colspan=\"4\">\n" + " Aus</td>\n" + "<td>&nbsp</td></tr>\n" + "<tr height=\"8\"><td></td></tr>\n" + "<tr><td colspan=\"7\">\n" + "<table align=\"top\" width=\"100%\"><tr>\n" + "<td width=\"182\"></td>\n" + "<td><hr size=\"1\"></font></td></tr>\n" + "<tr><td height=\"5\"></td></tr></table>\n" + "</td></tr>\n" + "<tr>\n" + "<td width=\"190\"></td>\n" + "<td colspan=\"2\">\n" + " <b>PV-Generator</b></td>\n" + "<td width=\"140\">&nbsp</td>\n" + "<td colspan=\"2\">\n" + " <b>Ausgangsleistung</b></td>\n" + "<td width=\"30\">&nbsp</td>\n" + "<td>&nbsp</td></tr>\n" + "<tr><td height=\"10\"></td></tr>\n" + "<tr>\n" + "<td width=\"190\"></td>\n" + "<td width=\"100\">\n" + " <u>String 1</u></td>\n" + "<td width=\"70\">&nbsp</td>\n" + "<td width=\"140\">&nbsp</td>\n" + "<td width=\"95\">\n" + " <u>L1</u></td>\n" + "<td width=\"70\">&nbsp</td>\n" + "<td width=\"30\">&nbsp</td>\n" + "<td>&nbsp</td></tr>\n" + "<tr>\n" + "<td width=\"190\"></td>\n" + "<td width=\"100\">\n" + " Spannung</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " x x x&nbsp</td>\n" + "<td width=\"140\">&nbsp V</td>\n" + "<td width=\"100\">\n" + " Spannung</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " x x x&nbsp</td>\n" + "<td width=\"30\">&nbsp V</td>\n" + "<td>&nbsp</td></tr>\n" + "<tr height=\"2\"><td></td></tr>\n" + "<tr valign=\"top\" align=\"left\">\n" + "<td width=\"190\">&nbsp</td>\n" + "<td width=\"100\">\n" + " Strom</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " x x x&nbsp</td>\n" + "<td width=\"140\">&nbsp A</td>\n" + "<td width=\"100\">\n" + " Leistung</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " x x x&nbsp</td>\n" + "<td width=\"30\">&nbsp W</td>\n" + "<td>&nbsp</td></tr>\n" + "<tr height=\"22\"><td></td></tr>\n" + "<tr>\n" + "<td width=\"190\"></td>\n" + "<td width=\"100\">\n" + " <u>String 2</u></td>\n" + "<td width=\"70\">&nbsp</td>\n" + "<td width=\"140\">&nbsp</td>\n" + "<td width=\"100\">\n" + " <u>L2</u></td>\n" + "<td width=\"70\">&nbsp</td>\n" + "<td width=\"30\">&nbsp</td>\n" + "<td>&nbsp</td></tr>\n" + "<tr>\n" + "<td width=\"190\"></td>\n" + "<td width=\"100\">\n" + " Spannung</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " x x x&nbsp</td>\n" + "<td width=\"140\">&nbsp V</td>\n" + "<td width=\"100\">\n" + " Spannung</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " x x x&nbsp</td>\n" + "<td width=\"30\">&nbsp V</td>\n" + "<td>&nbsp</td></tr>\n" + "<tr height=\"2\"><td></td></tr>\n" + "<tr valign=\"top\" align=\"left\">\n" + "<td width=\"190\">&nbsp</td>\n" + "<td width=\"100\">\n" + " Strom</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " x x x&nbsp</td>\n" + "<td width=\"140\">&nbsp A</td>\n" + "<td width=\"100\">\n" + " Leistung</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " x x x&nbsp</td>\n" + "<td width=\"30\">&nbsp W</td>\n" + "<td>&nbsp</td></tr>\n" + "<tr height=\"22\"><td></td></tr>\n" + "<tr>\n" + "<td width=\"190\"></td>\n" + "<td width=\"100\">\n" + " <u>String 3</u></td>\n" + "<td width=\"70\">&nbsp</td>\n" + "<td width=\"140\">&nbsp</td>\n" + "<td width=\"100\">\n" + " <u>L3</u></td>\n" + "<td width=\"70\">&nbsp</td>\n" + "<td width=\"30\">&nbsp</td>\n" + "<td>&nbsp</td></tr>\n" + "<tr>\n" + "<td width=\"190\"></td>\n" + "<td width=\"100\">\n" + " Spannung</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " x x x&nbsp</td>\n" + "<td width=\"140\">&nbsp\n" + " V</td>\n" + "<td width=\"95\">\n" + " Spannung</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " x x x&nbsp</td>\n" + "<td width=\"30\">&nbsp V</td>\n" + "<td>&nbsp</td></tr>\n" + "<tr height=\"2\"><td></td></tr>\n" + "<tr valign=\"top\" align=\"left\">\n" + "<td width=\"190\">&nbsp</td>\n" + "<td width=\"95\">\n" + " Strom</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " x x x&nbsp</td>\n" + "<td width=\"140\">&nbsp\n" + "A</td>\n" + "<td width=\"95\">\n" + " Leistung</td>\n" + "<td width=\"70\" align=\"right\" bgcolor=\"#FFFFFF\">\n" + " x x x&nbsp</td>\n" + "<td width=\"30\">&nbsp W</td>\n" + "<td>&nbsp</td></tr>\n\n" + "<tr><td height=\"15\"></td></tr>\n" + "<tr><td colspan=\"7\">\n" + "<table align=\"top\" width=\"100%\">\n" + "<tr><td width=\"182\"></td>\n" + "<td><hr size=\"1\"></font></td>\n" + "</tr><tr><td height=\"5\"></td></tr></table>\n" + "</td></tr></table>\n" + "<table cellspacing=\"0\" cellpadding=\"0\" width=\"770\">\n" + "<tr><td width=\"190\"></td>\n" + "<td><font face=\"Arial,Helvetica,Geneva,Sans-serif\">\n" + "<b>RS485 Kommunikation</b></td></tr>\n" + "<tr><td height=\"8\"></td></tr>\n" + "<tr><td width=\"190\"></td>\n" + "<td><font face=\"Arial,Helvetica,Geneva,Sans-serif\">\n" + "Wechselrichter&nbsp\n" + "<input type=\"Text\" name=\"edWrNr\" value=\"220\" size=\"3\" maxlength=\"3\">\n" + "<input type=\"submit\" value=\"Anzeigen/Aktualisieren\">\n" + "</td></tr><tr><td height=\"10\"></td></tr>\n" + "</table>\n" + "</td></tr></table></font>\n\n" + "<hr>\n" + "<table cellspacing=\"0\" cellpadding=\"0\" width=\"770\">\n" + "<tr><td height=\"5\"></td></tr>\n" + "<tr><td width=\"190\"></td>\n" + "<td width=\"330\">\n" + "<font face=\"Arial,Helvetica,Geneva,Sans-serif,sans-serif\">\n" + "<a href=\"LogDaten.dat\">Historie</a>\n" + "&nbsp &nbsp &nbsp\n" + "<a href=\"Info.fhtml\">Infoseite</a></font></td>\n" + "<td align=\"right\">\n" + "<font face=\"Arial,Helvetica,Geneva,Sans-serif,sans-serif\">\n" + "<a href=\"Solar2.fhtml\">Einstellungen</a></font></td>\n" + "<td width=\"50\"></td>\n" + "</tr></table></font>\n" + "</form>\n" + "</body>\n" + "</html>\n"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html