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

Substitution

Processing...

Code Generator

Generated Code

#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox Local $sRegex = "(?m)^(.*?) \d{1,2}\/ ?(\d{1,2})\/ ?\d{4}(?: (?:ONE DAY|(?:\d{1,2}\/ ?(\d{1,2})\/ ?\d{4})))? (.*)$" Local $sString = "Forest Moon 12/2/2018 12/3/2018 Assault Battles" & @CRLF & _ "Home One 12/5/2018 ONE DAY Fleet Mastery" & @CRLF & _ "The Artist of War 12/ 6/ 2018 12/ 12/ 2018 Legendary" & @CRLF & _ "Chimera 12/7/2018 12/ 13/ 2018 Legendary" & @CRLF & _ "Endor Escalation 12/8/2018 ONE DAY Heroic" & @CRLF & _ "" & @CRLF & _ "The Artist of War 12/8/2018 12/9/2018 Mythic" & @CRLF & _ "" & @CRLF & _ "Ground War 12/ 10/2018 12/ 11/2018 Assault Battles" & @CRLF & _ "Ewoks and Empire 12/13/2018 ONE DAY Omega Battles" & @CRLF & _ "Executrix 12/ 15/2018 ONE DAY Fleet Mastery" & @CRLF & _ "Rebel Round-Up 12/ 16/2018 12/ 17/ 2018 Assault Battles" & @CRLF & _ "Secrets and Shadows 12/ 19/ 2018 12/ 20/2018 Assault Battles" & @CRLF & _ "Endurance 12/ 21/2018 ONE DAY Fleet Mastery" & @CRLF & _ "Military Might 12/ 22/2018 12/ 23/2018 Assault Battles" & @CRLF & _ "Ghosts of Dathomir 12/22/2018 ONE DAY Special Event" & @CRLF & _ "Rebels and Geonosians 12/24/2018 ONE DAY Omega Battles" & @CRLF & _ "Ground War 12/24/2018 12/25/ 2018 Assault Battles" & @CRLF & _ "Grandmaster's Training 12/24/2018 12/25/2018 Mythic" & @CRLF & _ "" & @CRLF & _ "Ewoks and Empire 12/25/2018 ONE DAY Omega Battles" & @CRLF & _ "Military Might 12/ 25/2018 12/ 26/2018 Assault Battles" & @CRLF & _ "Executrix 12/ 25/ 2018 ONE DAY Fleet Mastery" & @CRLF & _ "The Artist of War 12/ 25/ 2018 12/ 26/ 2018 Mythic" & @CRLF & _ "" & @CRLF & _ "One Famous Wookie 12/25/2018 1/8/2019 Legendary" & @CRLF & _ "" & @CRLF & _ "Jedi and Tusken 12/26/2018 ONE DAY Omega Battles" & @CRLF & _ "Forest Moon 12/26/2018 12/27/2018 Assault Battles" & @CRLF & _ "Home One 12/26/2018 ONE DAY Fleet Mastery" & @CRLF & _ "Sith and Droids 12/27/2018 ONE DAY Omega Battles" & @CRLF & _ "Secrets and Shadows 12/ 27/ 2018 12/ 28/2018 Assault Battles" & @CRLF & _ "Endurance 12/27/2018 ONE DAY Fleet Mastery" & @CRLF & _ "Emperor's Demise 12/ 27/ 2018 12/ 28/ 2018 Mythic" & @CRLF & _ "Nightsisters and Jawas 12/28/2018 ONE DAY Omega Battles" & @CRLF & _ "Geonosian Fleet Advanced Tactic 12/28/2018 ONE DAY Fleet Mastery" & @CRLF & _ "Rebel Round-Up 12/28/2018 12/29/2018 Assault Battles" & @CRLF & _ "Daring Droid 12/ 28/ 2018 12/ 29/ 2018 Mythic" & @CRLF & _ "Resistance and Clones 12/29/2018 ONE DAY Omega Battles" & @CRLF & _ "Places of Power 12/ 29/2018 12/ 30/2018 Assault Battles" & @CRLF & _ "Pieces and Plans 12/29/2018 12/ 30/2018 Mythic" & @CRLF & _ "" & @CRLF & _ "First Order and Scoundrels 12/30/2018 ONE DAY Omega Battles" & @CRLF & _ "Defense of Dathomir 12/31/2018 1/1/2019 Heroic" & @CRLF & _ "|" & @CRLF & _ "ITB START DATE" & @CRLF & _ "" & @CRLF & _ "Imperial Retaliation 12/3/2018 Territory Battle ‘" & @CRLF & _ "Rebel Assault 12/ 13/2018 Territory Battle l" & @CRLF & _ "Imperial Retaliation 12/ 20/ 2018 Territory Battle" & @CRLF & _ "TW PREVIEW PHASE" & @CRLF & _ "" & @CRLF & _ "War 53-A 12/ 1/ 2018 Territory War" & @CRLF & _ "War 54-8 12/ 11/ 2018 Territory War |" & @CRLF & _ "War 55—A 12/ 29/ 2018 Territory War" & @CRLF & _ "War 56-3 1/ 2/ 2018 Territory War ‘" Local $sSubst = "$2-$3.......$4 - $1" Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst) MsgBox($MB_SYSTEMMODAL, "Result", $sResult)

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