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

/
/
gm

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 = "(?m)(?:\b(?P<month>0?[1-9]|0?1[012])[\/-](?P<day>0?[1-9]|[12][0-9]|3[01])[\/-](?P<year>\d{2,4})\b)|(?:(?P<month1>0?[1-9]|1[012])[\/](?P<year1>\d{4})\b)|(?:\b(?P<month2>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]{0,6}[. \/-]+(?P<day2>0?[1-9]|[12][0-9]|3[01])(?:th|st|nd)?[ ,\/-]+(?P<year2>\d{2,4})\b)|(?:\b(?P<day3>0?[1-9]|[12][0-9]|3[01])[ ,\/-]+(?P<month3>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]{0,6}[,. \/-]+(?P<year3>\d{2,4})\b)|(?:(?P<month4>Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]{0,6}[,. \/-]+(?P<year4>\d{2,4})\b)|(?:(?P<year5>[12]\d{3})\b)" Local $sString = "" & @CRLF & _ "04/20/2009; 04/20/09; 4/20/09; 4/3/09" & @CRLF & _ "Mar-20-2009; Mar 20, 2009; March 20, 2009; Mar. 20, 2009; Mar 20 2009;" & @CRLF & _ "20 Mar 2009; 20 March 2009; 20 Mar. 2009; 20 March, 2009" & @CRLF & _ "Mar 20th, 2009; Mar 21st, 2009; Mar 22nd, 2009" & @CRLF & _ "Feb 2009; Sep 2009; Oct 2010" & @CRLF & _ "6/2008; 12/2009" & @CRLF & _ "2009; 2010" & @CRLF & _ "011/14/83" & @CRLF & _ "16/22 " & @CRLF & _ "9/22" & @CRLF & _ "r1978" & @CRLF & _ "n4/2004" & @CRLF & _ "e12/2007" & @CRLF & _ "08-810-7787" & @CRLF & _ "pOct 2015" & @CRLF & _ "Janaury 1993" & @CRLF & _ "Married to husband for 50+ years" & @CRLF & _ "" & @CRLF & _ "0 03/25/93 Total time of visit (in minutes):\n" & @CRLF & _ "1 6/18/85 Primary Care Doctor:\n" & @CRLF & _ "2 sshe plans to move as of 7/8/71 In-Home Servic..." & @CRLF & _ "3 7 on 9/27/75 Audit C Score Current:\n" & @CRLF & _ "4 2/6/96 sleep studyPain Treatment Pain Level (N..." & @CRLF & _ "5 .Per 7/06/79 Movement D/O note:\n" & @CRLF & _ "6 4, 5/18/78 Patient's thoughts about current su..." & @CRLF & _ "7 10/24/89 CPT Code: 90801 - Psychiatric Diagnos..." & @CRLF & _ "8 3/7/86 SOS-10 Total Score:\n" & @CRLF & _ "9 (4/10/71)Score-1Audit C Score Current:\n" & @CRLF & _ "10 (5/11/85) Crt-1.96, BUN-26; AST/ALT-16/22; WBC..." & @CRLF & _ "11 4/09/75 SOS-10 Total Score:\n" & @CRLF & _ "12 8/01/98 Communication with referring physician..." & @CRLF & _ "13 1/26/72 Communication with referring physician..." & @CRLF & _ "14 5/24/1990 CPT Code: 90792: With medical servic..." & @CRLF & _ "15 1/25/2011 CPT Code: 90792: With medical servic..." & @CRLF & _ "16 4/12/82 Total time of visit (in minutes):\n" & @CRLF & _ "17 1; 10/13/1976 Audit C Score, Highest/Date:\n" & @CRLF & _ "18 4, 4/24/98 Relevant Drug History:\n" & @CRLF & _ "19 ) 59 yo unemployed w referred by Urgent Care f..." & @CRLF & _ "20 7/21/98 Total time of visit (in minutes):\n" & @CRLF & _ "21 10/21/79 SOS-10 Total Score:\n" & @CRLF & _ "22 3/03/90 CPT Code: 90792: With medical services\n" & @CRLF & _ "23 2/11/76 CPT Code: 90792: With medical services\n" & @CRLF & _ "24 07/25/1984 CPT Code: 90791: No medical services\n" & @CRLF & _ "25 4-13-82 Other Child Mental Health Outcomes Sca..." & @CRLF & _ "26 9/22/89 CPT Code: 90792: With medical services\n" & @CRLF & _ "27 9/02/76 CPT Code: 90791: No medical services\n" & @CRLF & _ "28 9/12/71 [report_end]\n" & @CRLF & _ "29 10/24/86 Communication with referring physicia..." 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