Regular Expressions 101

Save & Share

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

/
/
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 = "\\\"ruleGroupId\\\":\\s*\\\"(?<ruleGroupId>[^\\\"]+)\\\",[\\r\\n](.+[\\r\\n]){2}(\\\"excludedRules\\\"\\:\\s\\[)([\\r\\n].+)[\\r\\n]\\\"exclusionType\\\"\\:\\s*\\\"(?<exclusionTpe>[^\\\"]+)"; final String string = "{\n" + "\"timestamp\": 1646229254523,\n" + "\"formatVersion\": 1,\n" + "\"webaclId\": \"arn:aws:wafv2:us-east-1:111111:regional/webacl/alb-stage-web-acl/26ac170c-03c4-4fd7-8fab-86e346789fef\",\n" + "\"terminatingRuleId\": \"Default_Action\",\n" + "\"terminatingRuleType\": \"REGULAR\",\n" + "\"action\": \"ALLOW\",\n" + "\"terminatingRuleMatchDetails\": [],\n" + "\"httpSourceName\": \"ALB\",\n" + "\"httpSourceId\": \"182116744736-app/ALB-Stage/fcc1f5f9483b035e\",\n" + "\"ruleGroupList\": [\n" + "{\n" + "\"ruleGroupId\": \"AWS#AWSManagedRulesAmazonIpReputationList\",\n" + "\"terminatingRule\": null,\n" + "\"nonTerminatingMatchingRules\": [],\n" + "\"excludedRules\": null\n" + "},\n" + "{\n" + "\"ruleGroupId\": \"AWS#AWSManagedRulesBotControlRuleSet\",\n" + "\"terminatingRule\": null,\n" + "\"nonTerminatingMatchingRules\": [],\n" + "\"excludedRules\": null\n" + "},\n" + "{\n" + "\"ruleGroupId\": \"AWS#AWSManagedRulesCommonRuleSet\",\n" + "\"terminatingRule\": null,\n" + "\"nonTerminatingMatchingRules\": [],\n" + "\"excludedRules\": [\n" + "{\n" + "\"exclusionType\": \"EXCLUDED_AS_COUNT\",\n" + "\"ruleId\": \"SizeRestrictions_BODY\"\n" + "}\n" + "]\n" + "},\n" + "{\n" + "\"ruleGroupId\": \"AWS#AWSManagedRulesKnownBadInputsRuleSet\",\n" + "\"terminatingRule\": null,\n" + "\"nonTerminatingMatchingRules\": [],\n" + "\"excludedRules\": null\n" + "}\n" + "],\n" + "\"rateBasedRuleList\": [],\n" + "\"nonTerminatingMatchingRules\": [],\n" + "\"requestHeadersInserted\": null,\n" + "\"responseCodeSent\": null,\n" + "\"httpRequest\": {\n" + "\"clientIp\": \"67.218.14.10\",\n" + "\"country\": \"US\",\n" + "\"headers\": [\n" + "{\n" + "\"name\": \"host\",\n" + "\"value\": \"sample.com\"\n" + "},\n" + "{\n" + "\"name\": \"content-length\",\n" + "\"value\": \"50362\"\n" + "},\n" + "{\n" + "\"name\": \"cache-control\",\n" + "\"value\": \"max-age=0\"\n" + "},\n" + "{\n" + "\"name\": \"sec-ch-ua\",\n" + "\"value\": \"\\\" Not A;Brand\\\";v=\\\"99\\\", \\\"Chromium\\\";v=\\\"98\\\", \\\"Microsoft Edge\\\";v=\\\"98\\\"\"\n" + "},\n" + "{\n" + "\"name\": \"sec-ch-ua-mobile\",\n" + "\"value\": \"?0\"\n" + "},\n" + "{\n" + "\"name\": \"sec-ch-ua-platform\",\n" + "\"value\": \"\\\"Windows\\\"\"\n" + "},\n" + "{\n" + "\"name\": \"origin\",\n" + "\"value\": \"https://sample.com\"\n" + "},\n" + "{\n" + "\"name\": \"upgrade-insecure-requests\",\n" + "\"value\": \"1\"\n" + "},\n" + "{\n" + "\"name\": \"dnt\",\n" + "\"value\": \"1\"\n" + "},\n" + "{\n" + "\"name\": \"content-type\",\n" + "\"value\": \"multipart/form-data; boundary=----WebKitFormBoundaryuXOFvh7iQjJkEJHm\"\n" + "},\n" + "{\n" + "\"name\": \"user-agent\",\n" + "\"value\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36 Edg/98.0.1108.62\"\n" + "},\n" + "{\n" + "\"name\": \"accept\",\n" + "\"value\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\"\n" + "},\n" + "{\n" + "\"name\": \"sec-fetch-site\",\n" + "\"value\": \"same-origin\"\n" + "},\n" + "{\n" + "\"name\": \"sec-fetch-mode\",\n" + "\"value\": \"navigate\"\n" + "},\n" + "{\n" + "\"name\": \"sec-fetch-user\",\n" + "\"value\": \"?1\"\n" + "},\n" + "{\n" + "\"name\": \"sec-fetch-dest\",\n" + "\"value\": \"document\"\n" + "},\n" + "{\n" + "\"name\": \"referer\",\n" + "\"value\": \"https://sample.com/DischargeDetail.aspx\"\n" + "},\n" + "{\n" + "\"name\": \"accept-encoding\",\n" + "\"value\": \"gzip, deflate, br\"\n" + "},\n" + "{\n" + "\"name\": \"accept-language\",\n" + "\"value\": \"en-US,en;q=0.9\"\n" + "},\n" + "{\n" + "\"name\": \"cookie\",\n" + "\"value\": \"_ga=GA1.3.84334902.1642521795; __RequestVerificationToken=-8kinKddCjKCZTws-wPmXDZTFg39urggswPnYm5Y15UwfIjspHqTj1hOPAXIaRPHL2cupyt2vO4Gb5QUExZGd6e5djS0v81kxt2pH22Ow9XiJYr2NPWB_BdQb-VmCUHVXbiVZZ5NwTfGDrXd2O0uD_gba4fM3PhkQUO5f9zs5381; _gid=GA1.2.249665053.1645964709; _ga_33R15ZN4N1=GS1.1.1645965393.6.0.1645965397.56; _ga=GA1.2.84334902.1642521795; ASP.NET_SessionId=1fnikipv2poi14r3doy4kb2w\"\n" + "}\n" + "],\n" + "\"uri\": \"/ReleaseRequest.aspx\",\n" + "\"args\": \"\",\n" + "\"httpVersion\": \"HTTP/2.0\",\n" + "\"httpMethod\": \"POST\",\n" + "\"requestId\": \"1-621f7706-5e8f4ea33e2dc0cc66b98797\"\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