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

/
/
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 = "\\/\\*[\\s\\S]*?\\*\\/|([^:]|^)\\/\\/.*$"; final String string = "/*!\n" + " * jQuery JavaScript Library v3.6.0\n" + " * https://jquery.com/\n" + " *\n" + " * Includes Sizzle.js\n" + " * https://sizzlejs.com/\n" + " *\n" + " * Copyright OpenJS Foundation and other contributors\n" + " * Released under the MIT license\n" + " * https://jquery.org/license\n" + " *\n" + " * Date: 2021-03-02T17:08Z\n" + " */\n" + "//hellow orld\n" + "( function( global, factory ) {\n" + "/*\n" + "Hell world\n" + "*/\n" + " \"use strict\";\n\n" + " if ( typeof module === \"object\" && typeof module.exports === \"object\" ) {\n\n" + " // For CommonJS and CommonJS-like environments where a proper `window`\n" + " // is present, execute the factory and get jQuery.\n" + " // For environments that do not have a `window` with a `document`\n" + " // (such as Node.js), expose a factory as module.exports.\n" + " // This accentuates the need for the creation of a real `window`.\n" + " // e.g. var jQuery = require(\"jquery\")(window);\n" + " // See ticket #14549 for more info.\n" + " module.exports = global.document ?\n" + " factory( global, true ) :\n" + " function( w ) {\n" + " if ( !w.document ) {\n" + " throw new Error( \"jQuery requires a window with a document https://jquery.org/license\" );\n" + " }\n" + " return factory( w );\n" + " };\n" + " } else {\n" + " factory( global );\n" + " }\n\n" + "// Pass this if window is not defined yet\n" + "} )( typeof window !== \"undefined\" ? window : this, function( window, noGlobal ) {\n\n" + "// Edge <= 12 - 13+, Firefox <=18 - 45+, IE 10 - 11, Safari 5.1 - 9+, iOS 6 - 9.1\n" + "// throw exceptions when non-strict code (e.g., ASP.NET 4.5) accesses strict mode\n" + "// arguments.callee.caller (trac-13335). But as of jQuery 3.0 (2016), strict mode should be common\n" + "// enough that all such attempts are guarded in a try block.\n" + "\"use strict\";\n\n" + "var arr = [];\n\n" + "var getProto = Object.getPrototypeOf;\n\n" + "var slice = arr.slice;\n\n" + "var flat = arr.flat ? function( array ) {\n" + " return arr.flat.call( array );\n" + "} : function( array ) {\n" + " return arr.concat.apply( [], array );\n" + "};\n\n\n" + "var push = arr.push;\n\n" + "var indexOf = arr.indexOf;\n\n" + "var class2type = {};\n\n" + "var toString = class2type.toString;\n\n" + "var hasOwn = class2type.hasOwnProperty;\n\n" + "var fnToString = hasOwn.toString;\n\n" + "var ObjectFunctionString = fnToString.call( Object );\n\n" + "var support = {};\n\n" + "var isFunction = function isFunction( obj ) {\n\n" + " // Support: Chrome <=57, Firefox <=52\n" + " // In some browsers, typeof returns \"function\" for HTML <object> elements\n" + " // (i.e., `typeof document.createElement( \"object\" ) === \"function\"`).\n" + " // We don't want to classify *any* DOM node as a function.\n" + " // Support: QtWeb <=3.8.5, WebKit <=534.34, wkhtmltopdf tool <=0.12.5\n" + " // Plus for old WebKit, typeof returns \"function\" for HTML collections\n" + " // (e.g., `typeof document.getElementsByTagName(\"div\") === \"function\"`). (gh-4756)\n" + " return typeof obj === \"function\" && typeof obj.nodeType !== \"number\" &&\n" + " typeof obj.item !== \"function\";\n" + " };\n\n\n" + "var isWindow = function isWindow( obj ) {\n" + " return obj != null && obj === obj.window;\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