Regular Expressions 101

Save & Share

  • Regex Version: ver. 52
  • 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

/
/
g

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 = "(?<=\"aspectRatio\"\\:\\s\\\")\\d+:\\d+"; final String string = "{\n" + " \"timeline\": {\n" + " \"background\": \"#---secondaryColor---\",\n" + " \"fonts\": [\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Arial-Black.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Arial-BoldItalicMT.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Arial-BoldMT.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Arial-ItalicMT.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Arial.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/ArialNarrow-Bold.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/ArialNarrow-BoldItalic.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/ArialNarrow-Italic.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/ArialNarrow.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Caveat-Regular.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Georgia-Bold.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Georgia-BoldItalic.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Georgia-Italic.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Georgia.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-Black.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-BlackItalic.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-Bold.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-BoldItalic.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-ExtraBold.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-ExtraBoldItalic.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-ExtraLight.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-ExtraLightItalic.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-Italic.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-Light.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-LightItalic.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-Regular.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-SemiBold.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/Nunito-SemiBoldItalic.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/TimesNewRomanPS-BoldItalicMT.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/TimesNewRomanPS-BoldMT.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/TimesNewRomanPS-ItalicMT.ttf\"\n" + " },\n" + " {\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/fonts/TimesNewRomanPSMT.ttf\"\n" + " }\n" + " ],\n" + " \"tracks\": [\n" + " {\n" + " \"clips\": [\n" + " {\n" + " \"asset\": {\n" + " \"type\": \"html\",\n" + " \"html\": \"<p>---eventName---</p><p class='date'>---openHouseDate---</p>\",\n" + " \"css\": \"p {font-family: '---primaryFont---'; text-align: center; ---primaryFontStyle---; color: #---secondaryColor---; font-size: 90px; line-height: 80%;} .date {font-size: 40px}\",\n" + " \"width\": 1080,\n" + " \"height\": 200\n" + " },\n" + " \"start\": 0,\n" + " \"length\": 4,\n" + " \"position\": \"top\",\n" + " \"offset\": {\n" + " \"y\": 0.02\n" + " }\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"clips\": [\n" + " {\n" + " \"asset\": {\n" + " \"type\": \"html\",\n" + " \"html\": \"<p class='address'>---propertyAddress---</p><p>---bedAmount--- Bed | ---bathAmount--- Bath</p><p>---propertySurface---</p><p>---currentPrice---</p>\",\n" + " \"css\": \"p {color: #---primaryColor---; text-align: center; font-size: 40px; ---primaryFontStyle---; font-family: '---primaryFont---'; line-height: 80%;} .address {font-size: 60px}\",\n" + " \"width\": 980,\n" + " \"height\": 320,\n" + " \"background\": \"#---secondaryColor---\"\n" + " },\n" + " \"start\": 0,\n" + " \"length\": 4,\n" + " \"position\": \"bottom\"\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"clips\": [\n" + " {\n" + " \"asset\": {\n" + " \"type\": \"luma\",\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/luma/Template31-22-1080x1350.jpg\"\n" + " },\n" + " \"start\": 0,\n" + " \"length\": 4\n" + " },\n" + " {\n" + " \"asset\": {\n" + " \"type\": \"html\",\n" + " \"html\": \"<div></div>\",\n" + " \"background\": \"#---primaryColor---\",\n" + " \"width\": 1080,\n" + " \"height\": 1350\n" + " },\n" + " \"start\": 0,\n" + " \"length\": 4,\n" + " \"position\": \"center\"\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"clips\": [\n" + " {\n" + " \"asset\": {\n" + " \"type\": \"html\",\n" + " \"html\": \"<p></p>\",\n" + " \"width\": 95,\n" + " \"height\": 695,\n" + " \"background\": \"#---secondaryColor---\"\n" + " },\n" + " \"start\": 0,\n" + " \"length\": 4,\n" + " \"position\": \"bottomLeft\"\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"clips\": [\n" + " {\n" + " \"asset\": {\n" + " \"type\": \"html\",\n" + " \"html\": \"<p></p>\",\n" + " \"width\": 95,\n" + " \"height\": 695,\n" + " \"background\": \"#---secondaryColor---\"\n" + " },\n" + " \"start\": 0,\n" + " \"length\": 4,\n" + " \"position\": \"bottomRight\"\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"clips\": [\n" + " {\n" + " \"asset\": {\n" + " \"type\": \"image\",\n" + " \"src\": \"---propertyPhoto1---\"\n" + " },\n" + " \"start\": 0,\n" + " \"length\": 4,\n" + " \"position\": \"bottom\",\n" + " \"fit\": \"crop\",\n" + " \"scale\": 0.8,\n" + " \"transition\": {\n" + " \"in\": \"carouselUpSlow\"\n" + " },\n" + " \"offset\": {\n" + " \"y---horizontalPhoto1---\": 0.24,\n" + " \"y---verticalPhoto1---\": 0.15\n" + " }\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"clips\": [\n" + " {\n" + " \"asset\": {\n" + " \"type\": \"html\",\n" + " \"html\": \"<p></p>\",\n" + " \"width\": 1080,\n" + " \"height\": 655,\n" + " \"background\": \"#---primaryColor---\"\n" + " },\n" + " \"start\": 0,\n" + " \"length\": 4,\n" + " \"position\": \"top\"\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"clips\": [\n" + " {\n" + " \"asset\": {\n" + " \"type\": \"html\",\n" + " \"html\": \"<p>---callToAction---</p>\",\n" + " \"css\": \"p {color: #000000; font-size: 58px; ---secondaryFontStyle---; font-family: '---secondaryFont---'}\",\n" + " \"width\": 900,\n" + " \"height\": 200\n" + " },\n" + " \"start\": 4,\n" + " \"length\": 3,\n" + " \"position\": \"top\",\n" + " \"transition\": {\n" + " \"in\": \"fade\"\n" + " }\n" + " },\n" + " {\n" + " \"asset\": {\n" + " \"type\": \"html\",\n" + " \"html\": \"<p class='big'>---agentFirstName--- ---agentLastName---</p><p>---agentTitle---</p><p>---agentEmail---</p><p>---agentPhone---</p><p class='small'><br />---agentFirmName---<br />---agentFirmAddress---<br />---agentFirmWebsite---</p>\",\n" + " \"css\": \"p {color: #000000; font-size: 30px; ---secondaryFontStyle---; font-family: '---secondaryFont---'; margin-top: 0; margin-bottom: 0} .big {font-size: 58px} .small {font-size: 24px}\",\n" + " \"width\": 900,\n" + " \"height\": 540\n" + " },\n" + " \"start\": 4,\n" + " \"length\": 3,\n" + " \"position\": \"bottom\",\n" + " \"offset\": {\n" + " \"y\": 0.02\n" + " },\n" + " \"transition\": {\n" + " \"in\": \"fade\"\n" + " }\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"clips\": [\n" + " {\n" + " \"asset\": {\n" + " \"type\": \"luma\",\n" + " \"src\": \"https://perry-template-assets.s3.us-east-2.amazonaws.com/luma/circle-1080x1350agent.jpg\"\n" + " },\n" + " \"start\": 4,\n" + " \"length\": 3\n" + " },\n" + " {\n" + " \"asset\": {\n" + " \"type\": \"html\",\n" + " \"html\": \"<div></div>\",\n" + " \"background\": \"#D9---secondaryColor---\",\n" + " \"width\": 1080,\n" + " \"height\": 1350\n" + " },\n" + " \"start\": 4,\n" + " \"length\": 3,\n" + " \"position\": \"center\"\n" + " }\n" + " ]\n" + " },\n" + " {\n" + " \"clips\": [\n" + " {\n" + " \"asset\": {\n" + " \"type\": \"image\",\n" + " \"src\": \"---agentPhoto---\"\n" + " },\n" + " \"start\": 4,\n" + " \"length\": 3,\n" + " \"fit\": \"crop\",\n" + " \"scale---horizontalAgentPhoto---\": 0.5,\n" + " \"scale---verticalAgentPhoto---\": 0.6,\n" + " \"position\": \"top\",\n" + " \"offset\": {\n" + " \"y---horizontalAgentPhoto---\": -0.12,\n" + " \"y---verticalAgentPhoto---\": -0.135\n" + " },\n" + " \"transition\": {\n" + " \"in\": \"fadeFast\"\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " ],\n" + " \"cache\": true\n" + " },\n" + " \"output\": {\n" + " \"format\": \"mp4\",\n" + " \"resolution\": \"1080\",\n" + " \"aspectRatio\": \"4:5\",\n" + " \"quality\": \"medium\",\n" + " \"poster\": {\n" + " \"capture\": 2\n" + " },\n" + " \"destinations\": [\n" + " {\n" + " \"provider\": \"shotstack\",\n" + " \"exclude\": true\n" + " }\n" + " ]\n" + " }\n" + "}"; final String subst = ""; 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.replaceAll(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