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

/
/
g

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 = "coords.*\\{[^\\}]+:.(\\d+),[^\\}]+:.(\\d*)\\n.*\\}"; final String string = "{\n" + " \"name\": \"Medicare Annual Wellness Visit\",\n" + " \"translate\": false,\n" + " \"in_battery\": false,\n" + " \"action\": \"submitTest.php\",\n" + " \"conditionals_file\": \"conditionals-mwc.js\",\n" + " \"alias\": \"MWC\",\n" + " \"pdf_template\": \"annual_wellness_questionnaire.pdf\",\n" + " \"info\": \"Please complete this checklist before seeing your doctor or nurse\",\n" + " \"questions\": [\n" + " {\n" + " \"title_eng\": \"What is your age?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"age\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 112,\n" + " \"x\": 38\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"Are you male or a female?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"gender\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 121,\n" + " \"x\": 38\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"During the past four weeks, has your physical and emotional health limited your social activities with family, friends and groups?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"state_slight\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 140,\n" + " \"x\": 38\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"During the past four weeks, how much body pain have you generally had?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"state_pain\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 154,\n" + " \"x\": 38\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"During the past four weeks, was someone available to help you if you wanted or needed help?<br/>(For example, if you felt very nervous, lonely or blue; got sick and had to stay in bed; needed someone to talk to; needed help with daily chores; or needed help just taking care of yourself.)\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"affirm_qty\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 174,\n" + " \"x\": 38\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"During the past four weeks, what was the hardest physical activity you could do for at least 2 minutes?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"state_grade\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 194,\n" + " \"x\": 38\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"Can you handle your own money without help?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"boolean\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 206,\n" + " \"x\": 38\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"During the past four weeks, how would you rate your health in general?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"state_rate\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 222.5,\n" + " \"x\": 39\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"How have things been going for you in the past four weeks?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"life\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 238,\n" + " \"x\": 39\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"Are you having difficulties driving your car?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"boolean_drive\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 248,\n" + " \"x\": 39\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"Do you always fasten your seat belt when you are in the car?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"boolean_drive_b\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 52,\n" + " \"x\": 136\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"How often during the past four weeks have you been bothered by falling or dizziness when standing?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"linear_gradation\",\n" + " \"range_type\": \"state_freq\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 87,\n" + " \"x\": 173\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"How often during the past four weeks have you been bothered by sexual problems?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"linear_gradation\",\n" + " \"range_type\": \"state_freq\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 94,\n" + " \"x\": 173\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"How often during the past four weeks have you had trouble eating well?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"linear_gradation\",\n" + " \"range_type\": \"state_freq\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 100,\n" + " \"x\": 173\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"How often during the past four weeks have you been bothered by teeth or denture problems?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"linear_gradation\",\n" + " \"range_type\": \"state_freq\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 105,\n" + " \"x\": 173\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"How often during the past four weeks have you been bothered by problems using the telephone?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"linear_gradation\",\n" + " \"range_type\": \"state_freq\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 112,\n" + " \"x\": 173\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"How often during the past four weeks have you been bothered by tiredness or fatigue?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"linear_gradation\",\n" + " \"range_type\": \"state_freq\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 117,\n" + " \"x\": 173\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"Have you fallen 2 or more times during the past year?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"boolean\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 136,\n" + " \"x\": 137\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"Are you afraid of falling?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"boolean\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 147,\n" + " \"x\": 137\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"Are you a smoker?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"boolean_smoker\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 157,\n" + " \"x\": 137\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"During the past four weeks, how many drinks of wine, beer or other alcoholic beverages did you have?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"freq_drinks\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 176,\n" + " \"x\": 137\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"Do you excercise for about 20 minutes three or more times a week?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"freq_exer\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 190,\n" + " \"x\": 137\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"Have you been given any information to help you with hazards in your home that may hurt you?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"boolean\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 204,\n" + " \"x\": 187\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"Have you been given any information to help you with keeping track of your medications?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"boolean\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 209,\n" + " \"x\": 187\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"How often have you had trouble taking medications the way you are told to take them?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"freq_meds\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 224,\n" + " \"x\": 137\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"How confident are you that you can control and manage most of your health problems?\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"\",\n" + " \"range_type\": \"state_confidence\",\n" + " \"is_last\": false,\n" + " \"coords\": {\n" + " \"y\": 238,\n" + " \"x\": 137\n" + " }\n" + " },\n" + " {\n" + " \"title_eng\": \"What is your race? (Check all that apply)\",\n" + " \"title_esp\": \"\",\n" + " \"scoring_method\": \"race\",\n" + " \"range_type\": \"race\",\n" + " \"is_last\": true,\n" + " \"coords\": {\n" + " \"y\": 243,\n" + " \"x\": 137\n" + " }\n" + " }\n" + " ]\n" + "}"; final Pattern pattern = Pattern.compile(regex); 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