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

Substitution
Processing...

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 = "(magnolia\\.develop)(s*=s*)(.+)"; final String string = "#--------------------------------------------\n" + "# Here we define some properties not\n" + "# configured in the config repository.\n" + "# They are used in common before the initialization\n" + "# of the repositories.\n" + "#\n" + "# WARNING: on Windows systems, either use the /\n" + "# to separate path elements, or escape the \\ with\n" + "# another \\, i.e C:\\\\magnolia\\\\data\\\\repositories\n" + "# or c:/magnolia/data/repositories\n" + "#--------------------------------------------\n" + "magnolia.home=${magnolia.app.rootdir}\n" + "# The directory to expose file system resources from\n" + "magnolia.resources.dir=${magnolia.home}\n" + "# Pattern to define which resources should be observed by ClasspathScanner\n" + "magnolia.resources.classpath.observation.pattern=.*\\\\.(ftl|yaml)$\n" + "# Directories relative to magnolia.resources.dir which will be excluded from FileResourceOrigin observation.\n" + "# Also see info.magnolia.resourceloader.file.FileSystemResourceOrigin#EXCLUDED_DIRECTORIES\n" + "#magnolia.resources.filesystem.observation.excludedDirectories=META-INF,WEB-INF,cache,docroot,logs,repositories,tmp\n" + "magnolia.cache.startdir=${magnolia.home}/cache\n" + "magnolia.upload.tmpdir=${magnolia.home}/tmp\n" + "magnolia.exchange.history=${magnolia.home}/history\n" + "magnolia.repositories.config=WEB-INF/config/default/repositories.xml\n" + "magnolia.repositories.home=${magnolia.home}/repositories\n" + "magnolia.repositories.jackrabbit.config=WEB-INF/config/repo-conf/jackrabbit-bundle-derby-search.xml\n\n" + "log4j.config=WEB-INF/config/default/log4j.xml\n" + "magnolia.logs.dir=${magnolia.home}/logs\n\n" + "# The directories in which the bootstrap files are searched\n" + "magnolia.bootstrap.dir=WEB-INF/bootstrap/author WEB-INF/bootstrap/common\n\n" + "# This is only used for the initial installation afterward the configuration in the config repository is used\n" + "# The value is saved in /server/admin\n" + "magnolia.bootstrap.authorInstance=true\n\n" + "# Some modules contain optional sample content. They will check this property to decide if they should install\n" + "# the sample data\n" + "magnolia.bootstrap.samples=true\n\n" + "# Activate UTF-8 support to pages\n" + "magnolia.utf8.enabled=false\n\n" + "# Switch to false to enhance the performance of the javascript generation and similar\n" + "magnolia.develop=false\n\n" + "# Change to point at your custom Vaadin widgetset and theme\n" + "# Your widgetset should always inherit magnolia's default widgetset (info.magnolia.widgetset.MagnoliaWidgetSet)\n" + "# Your theme should always include magnolia's default theme (admincentral)\n" + "magnolia.ui.vaadin.widgetset=info.magnolia.widgetset.MagnoliaWidgetSet\n" + "magnolia.ui.vaadin.theme=admincentral\n\n" + "# Contact details displayed in the footer of the login form\n" + "#magnolia.service.contact=\n\n" + "#--------------------------------------------\n" + "# Repository connection\n" + "#--------------------------------------------\n" + "magnolia.connection.jcr.userId = admin\n" + "magnolia.connection.jcr.password = admin\n\n" + "# Set it to true if bootstrapping/update should be performed automatically\n" + "magnolia.update.auto=false\n\n" + "# Location of the file containing both the private and the public keys used to verify authenticity of activation requests\n" + "# This file is generated if not present\n" + "magnolia.author.key.location=${magnolia.home}/WEB-INF/config/default/magnolia-activation-keypair.properties\n"; final String subst = "$1$2true"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(string); // The substituted value will be contained in the result variable final String result = matcher.replaceFirst(subst); System.out.println("Substitution result: " + result); } }

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