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 = "(In\s(?P<lang>[^-]+))?(?(1)-|)((?P<home>.+)\svs\.\s+(?P<away>.+)\s+)\((?P<league>[^\)]+)" Local $sString = "In Spanish-Vitesse vs. Feyenoord (Eredivisie)" & @CRLF & _ "Vitesse vs. Feyenoord (Eredivisie)" & @CRLF & _ "Hyderabad vs. Mumbai City FC (Indian Super League)" & @CRLF & _ "Kilmarnock vs. Aberdeen (Scottish Premier League)" & @CRLF & _ "In Spanish-ADO Den Haag vs. Ajax (Eredivisie)" & @CRLF & _ "ADO Den Haag vs. Ajax (Eredivisie)" & @CRLF & _ "Sassuolo vs. AC Milan (Serie A)" & @CRLF & _ "In Spanish-Sassuolo vs. AC Milan (Serie A)" & @CRLF & _ "Cagliari vs. Udinese (Serie A)" & @CRLF & _ "In Spanish-Inter vs. Spezia (Serie A)" & @CRLF & _ "Inter Milan vs. Spezia (Serie A)" & @CRLF & _ "Benevento vs. Genoa (Serie A)" & @CRLF & _ "Kerala Blasters FC vs. SC East Bengal (Indian Super League)" & @CRLF & _ "Celtic vs. Heart of Midlothian (Final) (Scottish Cup)" & @CRLF & _ "Sport-Club Freiburg vs. Hertha BSC (Bundesliga)" & @CRLF & _ "Abilene Christian vs. Stetson (W Basketball)" & @CRLF & _ "In Spanish-VfL Wolfsburg vs. VfB Stuttgart (Bundesliga)" & @CRLF & _ "VfL Wolfsburg vs. VfB Stuttgart (Bundesliga)" & @CRLF & _ "In Spanish-Atalanta vs. AS Roma (Serie A)" & @CRLF & _ "Atalanta vs. AS Roma (Serie A)" & @CRLF & _ "Kobenhaven vs. OB (Danish Superliga)" & @CRLF & _ "East Carolina vs. Cincinnati (W Basketball)" & @CRLF & _ "Delaware vs. George Washington (W Basketball)" & @CRLF & _ "Northern Kentucky vs. Purdue Fort Wayne (W Basketball)" & @CRLF & _ "Jackson State vs. Iowa State (M Basketball)" & @CRLF & _ "Cleveland State vs. IUPUI (W Basketball)" & @CRLF & _ "Western Carolina vs. Georgia State (W Basketball)" & @CRLF & _ "Robert Morris vs. Milwaukee (W Basketball)" & @CRLF & _ "Albany vs. UMBC (W Basketball)" & @CRLF & _ "SMU vs. Temple (W Basketball)" & @CRLF & _ "Appalachian State vs. East Tennessee State (W Basketball)" & @CRLF & _ "Binghamton vs. Stony Brook (W Basketball)" & @CRLF & _ "UMass Lowell vs. Vermont (W Basketball)" & @CRLF & _ "Alice Lloyd vs. UNC Greensboro (M Basketball)" & @CRLF & _ "UNC Asheville vs. High Point (W Basketball)" & @CRLF & _ "Ball State vs. Akron (W Basketball)" & @CRLF & _ "South Carolina State vs. Campbell (W Basketball)" & @CRLF & _ "Oakland vs. Wright State (W Basketball)" & @CRLF & _ "VCU vs. Richmond (W Basketball)" & @CRLF & _ "Lazio vs. Napoli (Serie A)" & @CRLF & _ "In Spanish-Lazio vs. Napoli (Serie A)" & @CRLF & _ "Freed-Hardeman (TN) vs. North Alabama (M Basketball)" & @CRLF & _ "Western Kentucky vs. Tennessee Tech (W Basketball)" & @CRLF & _ "Chicago State vs. Drake (M Basketball)" & @CRLF & _ "Martin Methodist vs. Troy (W Basketball)" & @CRLF & _ "Louisiana vs. Louisiana Tech (W Basketball)" & @CRLF & _ "Champion Christian vs. Arkansas State (M Basketball)" & @CRLF & _ "Alcorn State vs. Houston (M Basketball)" & @CRLF & _ "Oakland vs. UIC (M Basketball)" & @CRLF & _ "Detroit Mercy vs. UIC (W Basketball)" & @CRLF & _ "Western Illinois vs. UT Martin (M Basketball)" & @CRLF & _ "NJIT vs. Temple (M Basketball)" & @CRLF & _ "Lamar vs. Texas State (W Basketball)" & @CRLF & _ "Converse vs. Coastal Carolina (W Basketball)" & @CRLF & _ "Flagler vs. North Florida (M Basketball)" & @CRLF & _ "Southeastern Louisiana vs. Tulane (W Basketball)" & @CRLF & _ "Iona vs. Rider (M Basketball)" & @CRLF & _ "McNeese State vs. Louisiana (M Basketball)" & @CRLF & _ "Crowley's Ridge vs. Tennessee State (M Basketball)" 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