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

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "coords.*\{[^}]+:.(\d+),[^}]+:.(\d*)\n.*}" Local $sString = "{" & @CRLF & _ " "name": "Medicare Annual Wellness Visit"," & @CRLF & _ " "translate": false," & @CRLF & _ " "in_battery": false," & @CRLF & _ " "action": "submitTest.php"," & @CRLF & _ " "conditionals_file": "conditionals-mwc.js"," & @CRLF & _ " "alias": "MWC"," & @CRLF & _ " "pdf_template": "annual_wellness_questionnaire.pdf"," & @CRLF & _ " "info": "Please complete this checklist before seeing your doctor or nurse"," & @CRLF & _ " "questions": [" & @CRLF & _ " {" & @CRLF & _ " "title_eng": "What is your age?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "age"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 112," & @CRLF & _ " "x": 38" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "Are you male or a female?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "gender"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 121," & @CRLF & _ " "x": 38" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "During the past four weeks, has your physical and emotional health limited your social activities with family, friends and groups?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "state_slight"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 140," & @CRLF & _ " "x": 38" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "During the past four weeks, how much body pain have you generally had?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "state_pain"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 154," & @CRLF & _ " "x": 38" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "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.)"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "affirm_qty"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 174," & @CRLF & _ " "x": 38" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "During the past four weeks, what was the hardest physical activity you could do for at least 2 minutes?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "state_grade"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 194," & @CRLF & _ " "x": 38" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "Can you handle your own money without help?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "boolean"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 206," & @CRLF & _ " "x": 38" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "During the past four weeks, how would you rate your health in general?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "state_rate"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 222.5," & @CRLF & _ " "x": 39" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "How have things been going for you in the past four weeks?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "life"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 238," & @CRLF & _ " "x": 39" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "Are you having difficulties driving your car?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "boolean_drive"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 248," & @CRLF & _ " "x": 39" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "Do you always fasten your seat belt when you are in the car?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "boolean_drive_b"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 52," & @CRLF & _ " "x": 136" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "How often during the past four weeks have you been bothered by falling or dizziness when standing?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": "linear_gradation"," & @CRLF & _ " "range_type": "state_freq"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 87," & @CRLF & _ " "x": 173" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "How often during the past four weeks have you been bothered by sexual problems?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": "linear_gradation"," & @CRLF & _ " "range_type": "state_freq"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 94," & @CRLF & _ " "x": 173" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "How often during the past four weeks have you had trouble eating well?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": "linear_gradation"," & @CRLF & _ " "range_type": "state_freq"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 100," & @CRLF & _ " "x": 173" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "How often during the past four weeks have you been bothered by teeth or denture problems?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": "linear_gradation"," & @CRLF & _ " "range_type": "state_freq"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 105," & @CRLF & _ " "x": 173" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "How often during the past four weeks have you been bothered by problems using the telephone?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": "linear_gradation"," & @CRLF & _ " "range_type": "state_freq"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 112," & @CRLF & _ " "x": 173" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "How often during the past four weeks have you been bothered by tiredness or fatigue?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": "linear_gradation"," & @CRLF & _ " "range_type": "state_freq"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 117," & @CRLF & _ " "x": 173" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "Have you fallen 2 or more times during the past year?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "boolean"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 136," & @CRLF & _ " "x": 137" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "Are you afraid of falling?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "boolean"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 147," & @CRLF & _ " "x": 137" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "Are you a smoker?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "boolean_smoker"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 157," & @CRLF & _ " "x": 137" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "During the past four weeks, how many drinks of wine, beer or other alcoholic beverages did you have?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "freq_drinks"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 176," & @CRLF & _ " "x": 137" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "Do you excercise for about 20 minutes three or more times a week?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "freq_exer"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 190," & @CRLF & _ " "x": 137" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "Have you been given any information to help you with hazards in your home that may hurt you?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "boolean"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 204," & @CRLF & _ " "x": 187" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "Have you been given any information to help you with keeping track of your medications?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "boolean"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 209," & @CRLF & _ " "x": 187" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "How often have you had trouble taking medications the way you are told to take them?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "freq_meds"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 224," & @CRLF & _ " "x": 137" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "How confident are you that you can control and manage most of your health problems?"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": ""," & @CRLF & _ " "range_type": "state_confidence"," & @CRLF & _ " "is_last": false," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 238," & @CRLF & _ " "x": 137" & @CRLF & _ " }" & @CRLF & _ " }," & @CRLF & _ " {" & @CRLF & _ " "title_eng": "What is your race? (Check all that apply)"," & @CRLF & _ " "title_esp": ""," & @CRLF & _ " "scoring_method": "race"," & @CRLF & _ " "range_type": "race"," & @CRLF & _ " "is_last": true," & @CRLF & _ " "coords": {" & @CRLF & _ " "y": 243," & @CRLF & _ " "x": 137" & @CRLF & _ " }" & @CRLF & _ " }" & @CRLF & _ " ]" & @CRLF & _ "}" Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aFullArray[0] For $i = 0 To UBound($aArray) -1 _ArrayConcatenate($aFullArray, $aArray[$i]) Next $aArray = $aFullArray ; Present the entire match result _ArrayDisplay($aArray, "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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm