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
No Match

r"
"
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 = "(?<=<h3>).*?(?=</h3>)"; final String string = "<!DOCTYPE HTML>\n" + "<html>\n\n" + "<head>\n" + " <title>black_pink_white - examples</title>\n" + " <meta name=\"description\" content=\"website description\" />\n" + " <meta name=\"keywords\" content=\"website keywords, website keywords\" />\n" + " <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />\n" + " <link rel=\"stylesheet\" type=\"text/css\" href=\"style/style.css\" title=\"style\" />\n" + "</head>\n\n" + "<body>\n" + " <div id=\"main\">\n" + " <div id=\"header\">\n" + " <div id=\"logo\">\n" + " <div id=\"logo_text\">\n" + " <!-- class=\"logo_colour\", allows you to change the colour of the text -->\n" + " <h1><a href=\"index.html\">black<span class=\"logo_colour\">_pink</span><span class=\"logo_colour2\">_white</span></a></h1>\n" + " <h2>Simple. Contemporary. Website Template.</h2>\n" + " </div>\n" + " </div>\n" + " <div id=\"menubar\">\n" + " <ul id=\"menu\">\n" + " <!-- put class=\"selected\" in the li tag for the selected page - to highlight which page you're on -->\n" + " <li><a href=\"index.html\">Home</a></li>\n" + " <li class=\"selected\"><a href=\"examples.html\">Examples</a></li>\n" + " <li><a href=\"page.html\">A Page</a></li>\n" + " <li><a href=\"another_page.html\">Another Page</a></li>\n" + " <li><a href=\"contact.html\">Contact Us</a></li>\n" + " </ul>\n" + " </div>\n" + " </div>\n" + " <div id=\"site_content\">\n" + " <div class=\"sidebar\">\n" + " <!-- insert your sidebar items here -->\n" + " <h3>Latest News</h3>\n" + " <h4>New Website Launched</h4>\n" + " <h5>August 1st, 2014</h5>\n" + " <p>2014 sees the redesign of our website. Take a look around and let us know what you think.<br /><a href=\"#\">Read more</a></p>\n" + " <p></p>\n" + " <h4>New Website Launched</h4>\n" + " <h5>August 1st, 2014</h5>\n" + " <p>2014 sees the redesign of our website. Take a look around and let us know what you think.<br /><a href=\"#\">Read more</a></p>\n" + " <h3>Useful Links</h3>\n" + " <ul>\n" + " <li><a href=\"#\">link 1</a></li>\n" + " <li><a href=\"#\">link 2</a></li>\n" + " <li><a href=\"#\">link 3</a></li>\n" + " <li><a href=\"#\">link 4</a></li>\n" + " </ul>\n" + " <h3>Search</h3>\n" + " <form method=\"post\" action=\"#\" id=\"search_form\">\n" + " <p>\n" + " <input class=\"search\" type=\"text\" name=\"search_field\" value=\"Enter keywords.....\" />\n" + " <input name=\"search\" type=\"image\" style=\"border: 0; margin: 0 0 -9px 5px;\" src=\"style/search.png\" alt=\"Search\" title=\"Search\" />\n" + " </p>\n" + " </form>\n" + " </div>\n" + " <div id=\"content\">\n" + " <!-- insert the page content here -->\n" + " <h1>Examples</h1>\n" + " <p>This page contains examples of all the styled elements available as part of this design. Use this page for reference, whilst you build your website.</p>\n" + " <h2>Headings</h2>\n" + " <p>These are the different heading formats:</p>\n" + " <h1>Heading 1</h1>\n" + " <h2>Heading 2</h2>\n" + " <h3>Heading 3</h3>\n" + " <h4>Heading 4</h4>\n" + " <h5>Heading 5</h5>\n" + " <h6>Heading 6</h6>\n" + " <h2>Text</h2>\n" + " <p>The following examples show how the text (within '&lt;p&gt;&lt;/p&gt;' tags) will appear:</p>\n" + " <p><strong>This is an example of bold text</strong></p>\n" + " <p><i>This is an example of italic text</i></p>\n" + " <p><a href=\"#\">This is a hyperlink</a></p>\n" + " <h2>Lists</h2>\n" + " <p>This is an unordered list:</p>\n" + " <ul>\n" + " <li>Item 1</li>\n" + " <li>Item 2</li>\n" + " <li>Item 3</li>\n" + " <li>Item 4</li>\n" + " </ul>\n" + " <p>This is an ordered list:</p>\n" + " <ol>\n" + " <li>Item 1</li>\n" + " <li>Item 2</li>\n" + " <li>Item 3</li>\n" + " <li>Item 4</li>\n" + " </ol>\n" + " <h2>Images</h2>\n" + " <p>images can be placed on the left, in the center or on the right:</p>\n" + " <span class=\"left\"><img src=\"style/graphic.png\" alt=\"example graphic\" /></span>\n" + " <p>\n" + " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor\n" + " incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud\n" + " exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute\n" + " irure dolor in reprehenderit in voluptate velit esse cillum.\n" + " </p>\n" + " <span class=\"center\"><img src=\"style/graphic.png\" alt=\"example graphic\" /></span>\n" + " <span class=\"right\"><img src=\"style/graphic.png\" alt=\"example graphic\" /></span>\n" + " <p>\n" + " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor\n" + " incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud\n" + " exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute\n" + " irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla\n" + " pariatur.\n" + " </p>\n" + " <h2>Tables</h2>\n" + " <p>Tables should be used to display data and not used for laying out your website:</p>\n" + " <table style=\"width:100%; border-spacing:0;\">\n" + " <tr><th>Item</th><th>Description</th></tr>\n" + " <tr><td>Item 1</td><td>Description of Item 1</td></tr>\n" + " <tr><td>Item 2</td><td>Description of Item 2</td></tr>\n" + " <tr><td>Item 3</td><td>Description of Item 3</td></tr>\n" + " <tr><td>Item 4</td><td>Description of Item 4</td></tr>\n" + " </table>\n" + " <h2>Form Elements</h2>\n" + " <form action=\"#\" method=\"post\">\n" + " <div class=\"form_settings\">\n" + " <p><span>Form field example</span><input type=\"text\" name=\"name\" value=\"\" /></p>\n" + " <p><span>Textarea example</span><textarea rows=\"8\" cols=\"50\" name=\"name\"></textarea></p>\n" + " <p><span>Checkbox example</span><input class=\"checkbox\" type=\"checkbox\" name=\"name\" value=\"\" /></p>\n" + " <p><span>Dropdown list example</span><select id=\"id\" name=\"name\"><option value=\"1\">Example 1</option><option value=\"2\">Example 2</option></select></p>\n" + " <p style=\"padding-top: 15px\"><span>&nbsp;</span><input class=\"submit\" type=\"submit\" name=\"name\" value=\"button\" /></p>\n" + " </div>\n" + " </form>\n" + " </div>\n" + " </div>\n" + " <div id=\"footer\">\n" + " Copyright &copy; black_pink_white | <a href=\"http://validator.w3.org/check?uri=referer\">HTML5</a> | <a href=\"http://jigsaw.w3.org/css-validator/check/referer\">CSS</a> | free from html5webtemplates.co.uk\n" + " </div>\n" + " </div>\n" + "</body>\n" + "</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