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 single character of: a, b, c or d
    [[ab][cd]]
  • 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]
  • Character class intersection
    [\w&&[^\d]]
  • 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
No Match

"
"
gm

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 = "(?<=(?:href|action|src)=[\\\"'])[^\\\"']+"; final String string = "This is JAVA Version You can use with Burp Suite :)\n\n\n" + "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" + "\"http://www.w3.org/TR/html4/loose.dtd\">\n" + "<html><!-- InstanceBegin template=\"/Templates/main_dynamic_template.dwt.php\" codeOutsideHTMLIsLocked=\"false\" -->\n" + "<head>\n" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-2\">\n\n" + "<!-- InstanceBeginEditable name=\"document_title_rgn\" -->\n" + "<title>logout</title>\n" + "<!-- InstanceEndEditable -->\n" + "<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\">\n" + "<!-- InstanceBeginEditable name=\"headers_rgn\" -->\n" + "<!-- here goes headers headers -->\n" + "<!-- InstanceEndEditable -->\n" + "<script language=\"JavaScript\" type=\"text/JavaScript\">\n" + "<!--\n" + "function MM_reloadPage(init) { //reloads the window if Nav4 resized\n" + " if (init==true) with (navigator) {if ((appName==\"Netscape\")&&(parseInt(appVersion)==4)) {\n" + " document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}\n" + " else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();\n" + "}\n" + "MM_reloadPage(true);\n" + "//-->\n" + "</script>\n\n" + "</head>\n" + "<body> \n" + "<div id=\"mainLayer\" style=\"position:absolute; width:700px; z-index:1\">\n" + "<div id=\"masthead\"> \n" + " <h1 id=\"siteName\"><a href=\"https://www.acunetix.com/\"><img src=\"images/logo.gif\" width=\"306\" height=\"38\" border=\"0\" alt=\"Acunetix website security\"></a></h1> \n" + " <h6 id=\"siteInfo\">TEST and Demonstration site for <a href=\"https://www.acunetix.com/vulnerability-scanner/\">Acunetix Web Vulnerability Scanner</a></h6>\n" + " <div id=\"globalNav\"> \n" + " <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr>\n" + " <td align=\"left\">\n" + " <a href=\"index.php\">home</a> | <a href=\"categories.php\">categories</a> | <a href=\"artists.php\">artists\n" + " </a> | <a href=\"disclaimer.php\">disclaimer</a> | <a href=\"cart.php\">your cart</a> | \n" + " <a href=\"guestbook.php\">guestbook</a> | \n" + " <a href=\"AJAX/index.php\">AJAX Demo</a>\n" + " </td>\n" + " <td align=\"right\">\n" + " </td>\n" + " </tr></table>\n" + " </div> \n" + "</div> \n" + "<!-- end masthead --> \n\n" + "<!-- begin content -->\n" + "<!-- InstanceBeginEditable name=\"content_rgn\" -->\n" + "<div id=\"content\">\n" + " <div class=\"story\">\n" + " <h1 id=\"pageName\">You have been logged out. See you back soon.</h1>\n" + " </div>\n" + "</div>\n" + "<!-- InstanceEndEditable -->\n" + "<!--end content -->\n\n" + "<div id=\"navBar\"> \n" + " <div id=\"search\"> \n" + " <form action=\"search.php?test=query\" method=\"post\"> \n" + " <label>search art</label> \n" + " <input name=\"searchFor\" type=\"text\" size=\"10\"> \n" + " <input name=\"goButton\" type=\"submit\" value=\"go\"> \n" + " </form> \n" + " </div> \n" + " <div id=\"sectionLinks\"> \n" + " <ul> \n" + " <li><a href=\"categories.php\">Browse categories</a></li> \n" + " <li><a href=\"artists.php\">Browse artists</a></li> \n" + " <li><a href=\"cart.php\">Your cart</a></li> \n" + " <li><a href=\"login.php\">Signup</a></li>\n" + " <li><a href=\"userinfo.php\">Your profile</a></li>\n" + " <li><a href=\"guestbook.php\">Our guestbook</a></li>\n" + " <li><a href=\"AJAX/index.php\">AJAX Demo</a></li>\n" + " </li> \n" + " </ul> \n" + " </div> \n" + " <div class=\"relatedLinks\"> \n" + " <h3>Links</h3> \n" + " <ul> \n" + " <li><a href='http://www.acunetix.com'>Security art</a></li> \n" + " <li><a href=\"https://www.acunetix.com/vulnerability-scanner/php-security-scanner/\">PHP scanner</a></li>\n" + " <li><a href=\"https://www.acunetix.com/blog/articles/prevent-sql-injection-vulnerabilities-in-php-applications/\">PHP vuln help</a></li>\n" + " <li><a href=\"http://www.eclectasy.com/Fractal-Explorer/index.html\">Fractal Explorer</a></li> \n" + " </ul> \n" + " </div> \n" + " <div id=\"advert\"> \n" + " <p>\n" + " <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"107\" height=\"66\">\n" + " <param name=\"movie\" value=\"Flash/add.swf\">\n" + " <param name=quality value=high>\n" + " <embed src=\"Flash/add.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"107\" height=\"66\"></embed>\n" + " </object>\n" + " </p>\n" + " </div> \n" + "</div> \n\n" + "<!--end navbar --> \n" + "<div id=\"siteInfo\"> <a href=\"http://www.acunetix.com\">About Us</a> | <a href=\"privacy.php\">Privacy Policy</a> | <a href=\"mailto:wvs@acunetix.com\">Contact Us</a> | &copy;2019\n" + " Acunetix Ltd \n" + "</div> \n" + "<br> \n" + "<div style=\"background-color:lightgray;width:100%;text-align:center;font-size:12px;padding:1px\">\n" + "<p style=\"padding-left:5%;padding-right:5%\"><b>Warning</b>: This is not a real shop. This is an example PHP application, which is intentionally vulnerable to web attacks. It is intended to help you test Acunetix. It also helps you understand how developer errors and bad configuration may let someone break into your website. You can use it to test other tools and your manual hacking skills as well. Tip: Look for potential SQL Injections, Cross-site Scripting (XSS), and Cross-site Request Forgery (CSRF), and more.</p>\n" + "</div>\n" + "</div>\n" + "</body>\n" + "<!-- InstanceEnd --></html>\n"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); 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