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

r"
"
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 = "(\w+)(?:(?:@)|(?:\s+[Aa][Tt]\s+))(.+)(?:(?:\.edu)|(?:\s+[dD][oO][Tt]\s+edu))" Local $sString = "ashishg e ashishg@stanford.edu" & @CRLF & _ "ashishg e rozm@stanford.edu" & @CRLF & _ "ashishg p 650-723-1614" & @CRLF & _ "ashishg p 650-723-4173" & @CRLF & _ "ashishg p 650-814-1478" & @CRLF & _ "balaji e balaji@stanford.edu" & @CRLF & _ "bgirod p 650-723-4539" & @CRLF & _ "bgirod p 650-724-3648" & @CRLF & _ "bgirod p 650-724-6354" & @CRLF & _ "cheriton e cheriton@cs.stanford.edu" & @CRLF & _ "cheriton e uma@cs.stanford.edu" & @CRLF & _ "cheriton p 650-723-1131" & @CRLF & _ "cheriton p 650-725-3726" & @CRLF & _ "dabo e dabo@cs.stanford.edu" & @CRLF & _ "dabo p 650-725-3897" & @CRLF & _ "dabo p 650-725-4671" & @CRLF & _ "dlwh e dlwh@stanford.edu" & @CRLF & _ "engler e engler@lcs.mit.edu" & @CRLF & _ "engler e engler@stanford.edu" & @CRLF & _ "eroberts e eroberts@cs.stanford.edu" & @CRLF & _ "eroberts p 650-723-3642" & @CRLF & _ "eroberts p 650-723-6092" & @CRLF & _ "fedkiw e fedkiw@cs.stanford.edu" & @CRLF & _ "hager e hager@cs.jhu.edu" & @CRLF & _ "hager p 410-516-5521" & @CRLF & _ "hager p 410-516-5553" & @CRLF & _ "hager p 410-516-8000" & @CRLF & _ "hanrahan e hanrahan@cs.stanford.edu" & @CRLF & _ "hanrahan p 650-723-0033" & @CRLF & _ "hanrahan p 650-723-8530" & @CRLF & _ "horowitz p 650-725-3707" & @CRLF & _ "horowitz p 650-725-6949" & @CRLF & _ "jks e jks@robotics.stanford.edu" & @CRLF & _ "jurafsky e jurafsky@stanford.edu" & @CRLF & _ "jurafsky p 650-723-5666" & @CRLF & _ "kosecka e kosecka@cs.gmu.edu" & @CRLF & _ "kosecka p 703-993-1710" & @CRLF & _ "kosecka p 703-993-1876" & @CRLF & _ "kunle e darlene@csl.stanford.edu" & @CRLF & _ "kunle e kunle@ogun.stanford.edu" & @CRLF & _ "kunle p 650-723-1430" & @CRLF & _ "kunle p 650-725-3713" & @CRLF & _ "kunle p 650-725-6949" & @CRLF & _ "lam e lam@cs.stanford.edu" & @CRLF & _ "lam p 650-725-3714" & @CRLF & _ "lam p 650-725-6949" & @CRLF & _ "latombe e asandra@cs.stanford.edu" & @CRLF & _ "latombe e latombe@cs.stanford.edu" & @CRLF & _ "latombe e liliana@cs.stanford.edu" & @CRLF & _ "latombe p 650-721-6625" & @CRLF & _ "latombe p 650-723-0350" & @CRLF & _ "latombe p 650-723-4137" & @CRLF & _ "latombe p 650-725-1449" & @CRLF & _ "levoy e ada@graphics.stanford.edu" & @CRLF & _ "levoy e melissa@graphics.stanford.edu" & @CRLF & _ "levoy p 650-723-0033" & @CRLF & _ "levoy p 650-724-6865" & @CRLF & _ "levoy p 650-725-3724" & @CRLF & _ "levoy p 650-725-4089" & @CRLF & _ "manning e dbarros@cs.stanford.edu" & @CRLF & _ "manning e manning@cs.stanford.edu" & @CRLF & _ "manning p 650-723-7683" & @CRLF & _ "manning p 650-725-1449" & @CRLF & _ "manning p 650-725-3358" & @CRLF & _ "nass e nass@stanford.edu" & @CRLF & _ "nass p 650-723-5499" & @CRLF & _ "nass p 650-725-2472" & @CRLF & _ "nick e nick.parlante@cs.stanford.edu" & @CRLF & _ "nick p 650-725-4727" & @CRLF & _ "ok p 650-723-9753" & @CRLF & _ "ok p 650-725-1449" & @CRLF & _ "ouster e teresa.lynn@stanford.edu" & @CRLF & _ "ouster e ouster@cs.stanford.edu" & @CRLF & _ "pal e pal@cs.stanford.edu" & @CRLF & _ "pal p 650-725-9046" & @CRLF & _ "psyoung e patrick.young@stanford.edu" & @CRLF & _ "rajeev p 650-723-4377" & @CRLF & _ "rajeev p 650-723-6045" & @CRLF & _ "rajeev p 650-725-4671" & @CRLF & _ "rinard e rinard@lcs.mit.edu" & @CRLF & _ "rinard p 617-253-1221" & @CRLF & _ "rinard p 617-258-6922" & @CRLF & _ "serafim e serafim@cs.stanford.edu" & @CRLF & _ "serafim p 650-723-3334" & @CRLF & _ "serafim p 650-725-1449" & @CRLF & _ "shoham e shoham@stanford.edu" & @CRLF & _ "shoham p 650-723-3432" & @CRLF & _ "shoham p 650-725-1449" & @CRLF & _ "subh e subh@stanford.edu" & @CRLF & _ "subh e uma@cs.stanford.edu" & @CRLF & _ "subh p 650-724-1915" & @CRLF & _ "subh p 650-725-3726" & @CRLF & _ "subh p 650-725-6949" & @CRLF & _ "thm e pkrokel@stanford.edu" & @CRLF & _ "thm p 650-725-3383" & @CRLF & _ "thm p 650-725-3636" & @CRLF & _ "thm p 650-725-3938" & @CRLF & _ "tim p 650-724-9147" & @CRLF & _ "tim p 650-725-2340" & @CRLF & _ "tim p 650-725-4671" & @CRLF & _ "ullman e support@gradiance.com" & @CRLF & _ "ullman e ullman@cs.stanford.edu" & @CRLF & _ "ullman p 650-494-8016" & @CRLF & _ "ullman p 650-725-2588" & @CRLF & _ "ullman p 650-725-4802" & @CRLF & _ "vladlen e vladlen@stanford.edu" & @CRLF & _ "widom e siroker@cs.stanford.edu" & @CRLF & _ "widom e widom@cs.stanford.edu" & @CRLF & _ "widom p 650-723-0872" & @CRLF & _ "widom p 650-723-7690" & @CRLF & _ "widom p 650-725-2588" & @CRLF & _ "zelenski e zelenski@cs.stanford.edu" & @CRLF & _ "zelenski p 650-723-6092" & @CRLF & _ "zelenski p 650-725-8596" & @CRLF & _ "zm e manna@cs.stanford.edu" & @CRLF & _ "zm p 650-723-4364" & @CRLF & _ "zm p 650-725-4671" & @CRLF & _ "650-725-4671" & @CRLF & _ "650-725-4671" & @CRLF & _ "6103564533" & @CRLF & _ "(610)3564533" & @CRLF & _ "(610) 356-4533 " & @CRLF & _ "610.405.0420" & @CRLF & _ "6104050420" & @CRLF & _ "16104050420" & @CRLF & _ "610.405-0420" & @CRLF & _ "610.405-0420" & @CRLF & _ "" & @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