Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
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
Processing...

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 = "(\\.amenity_icon\\..*)\"|<h4>(.*)<\\/h4>|<p>(.*)<\\/p>"; final String string = "function LoadTooltips() {\n" + " $(\".units_table .amenity_icon.icon_climate\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Temperature Controlled</h4><p>Units are heated and/or cooled. See manager for details.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_secure\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Secure Units</h4><p>Units protected with advanced security features.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_driveup\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Drive-up Access</h4><p>Plenty of room to park your vehicle in front of your storage unit.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_wine\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Wine Storage</h4><p>Specialty space with temperature control for wines.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_vehicle\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>RV, Car, Boat Parking</h4><p>Larger parking spaces for grown-up toys (indoors or outdoors).</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_mobile\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Portable Storage</h4><p>We bring the unit to you and then store it at our secure location.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_twentyfour\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>24 Hour Access</h4><p>Units are accessible 24 hours a day.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_elevator\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Elevator Access</h4><p>Reduce heavy lifting and easily access your storage unit with our elevator.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_interior\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Interior Storage</h4><p>Indoor units provide added protection against weather and theft.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_ramp\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Ramp</h4><p>Ramps make it easy to maneuver dollies – which means less lifting for you!</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_covered_parking\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Covered Parking</h4><p>Need protection from the elements? Check out our covered parking.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_uncovered_parking\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Uncovered Parking</h4><p>The most affordable option for parking your vehicle at our secure location.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_ground_floor\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Ground Floor</h4><p>Reduce your heavy lifting by taking advantage of our ground level units.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_upstairs\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Upstairs</h4><p>Looking to save money? Try our upstairs units for added savings.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_conference\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Conference Room</h4><p>Need a conference room for important client meetings? Take advantage of ours.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_fenced\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Fenced & Gated</h4><p>Perimeter fencing and gate entry give your unit 360 degree protection.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_kiosk\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>24 Hour Kiosk</h4><p>Rent storage units, make payments and more with our convenient 24 hour kiosk.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_resident\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Resident Manager</h4><p>Our resident manager lives onsite for added security and customer service.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_dollies\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Dollies/Handcarts</h4><p>Loading and unloading is easy with our complimentary handcarts & dollies.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_shipping\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Shipping Services</h4><p>Skip the long lines at the post office and ship your packages at our facility!</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_callcenter\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Call Center</h4><p>Through our call center, you can reserve your unit when it's convenient for you.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_camera\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Security Cameras</h4><p>Fenced or gated area with recorded video surveillance.</p></div>\"\n" + " }\n" + " });\n" + " $(\".units_table .amenity_icon.icon_power\").tooltip({\n" + " track: false,\n" + " delay: 0,\n" + " showURL: false,\n" + " left: -126,\n" + " top: -100,\n" + " bodyHandler: function () {\n" + " return \"<div class=\\\"sidebar_tooltip\\\"><h4>Power</h4><p>Electrical outlets within or near your unit.</p></div>\"\n" + " }\n" + " });\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