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

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

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx