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 = "\\[\\[#(.*)\\|(.*)\\]\\]"; final String string = "<languages/>\n" + "<translate>\n" + "{{TNT|Unmaintained extension}}\n" + "{{ {{TNTN|Extension}}\n" + "|name = Agora\n" + "|type1 = skin\n" + "|type2 = \n" + "|status = unmaintained\n" + "|hook1 = BeforePageDisplay\n" + "|image = 2013-04-22_Agora_detail_screenshot.png\n" + "|author = Rob Moen, Trevor Parscal, Munaf Assaf\n" + "|description = Adds skin-agnostic styles to MediaWiki\n" + "|license = {{ {{TNTN|EL}} |GNUGPL2+}}\n" + "|mediawiki = 1.19 - 1.21\n" + "|version = 0.0.1\n" + "|update = 2013-04-04\n" + "|download = {{ {{TNTN|WikimediaDownload}} |Agora}}\n" + "|readme = {{git file|action=raw|project=mediawiki/extensions/Agora|file=README|text=README}}\n" + "|needs-updatephp = no\n" + "|parameters = * $wgAgoraEnabledSiteWide\n" + "* $wgAgoraEnabledPages\n" + "* $wgAgoraEnabledActions\n" + "|example =\n" + "}}\n\n" + "The '''Agora''' extension added skin-agnostic CSS styles to MediaWiki,\n" + "following the [[Special:MyLanguage/Wikimedia Foundation Design|Wikimedia Foundation Design]] principles.\n" + "The CSS defines various mw-ui-* classes including\n" + "* <code>.mw.ui-button</code> with many variations\n" + "* <code>.mw-ui-vform</code> for a container with a vertical \"stacked\" layout\n" + "* several utility classes such as <code>mw-ui-flush-left</code>\n\n" + "Its test subdirectory has some static HTML pages illustrating their use.\n\n" + "== Also in 1.22 core ==\n\n" + "As of {{gerrit|55847}}, the same CSS is available in core MediaWiki in release 1.22wmf2 in the [[Special:MyLanguage/ResourceLoader/Default_modules#mediawiki.ui|mediawiki.ui]] module, and you don't need this extension. In release 1.23, the CSS for buttons is split out into a [[Special:MyLanguage/ResourceLoader/Default_modules#mediawiki.ui.button|mediawiki.ui.button]] module.\n" + "Thus you can use ''context''<code>->getOutput()->addModuleStyles( 'mediawiki.ui' )</code> to ensure the CSS in core is loaded.\n\n" + "==Installation==\n\n" + "{{TNT|ExtensionInstall}}\n" + "Consult its README file to decide how to enable the extension in pages on your wiki and set its globals accordingly in LocalSettings.php\n\n" + "=== Verifying the installation ===\n\n" + "On a page where the extension should provide its CSS according to your configuration, create a submit button and give it the styles 'mw-ui-button blue'.\n\n" + "To see if the extension is sent down on the current page, in a browser console enter <kbd>mw.loader.state( 'ext.agora.base' )</kbd>; it should return \"ready\".\n\n" + "=== Compass ===\n\n" + "The extension's CSS was generated from [[w:Sass (stylesheet language)|Sass]] <tt>.sccs</tt> files using [http://compass-style.org/ Compass].\n" + "You don't need Compass to use the CSS files in <tt>modules/css</tt>. Click [[#Installation|installation]].\n\n" + "[[Category:Agora{{translation}}|Category:Agora{{translation}}]]\n" + "</translate>"; final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); 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