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

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"^(.*?) \d{1,2}\/ ?(\d{1,2})\/ ?\d{4}(?: (?:ONE DAY|(?:\d{1,2}\/ ?(\d{1,2})\/ ?\d{4})))? (.*)$"; string substitution = @"$2-$3.......$4 - $1"; string input = @"Forest Moon 12/2/2018 12/3/2018 Assault Battles Home One 12/5/2018 ONE DAY Fleet Mastery The Artist of War 12/ 6/ 2018 12/ 12/ 2018 Legendary Chimera 12/7/2018 12/ 13/ 2018 Legendary Endor Escalation 12/8/2018 ONE DAY Heroic The Artist of War 12/8/2018 12/9/2018 Mythic Ground War 12/ 10/2018 12/ 11/2018 Assault Battles Ewoks and Empire 12/13/2018 ONE DAY Omega Battles Executrix 12/ 15/2018 ONE DAY Fleet Mastery Rebel Round-Up 12/ 16/2018 12/ 17/ 2018 Assault Battles Secrets and Shadows 12/ 19/ 2018 12/ 20/2018 Assault Battles Endurance 12/ 21/2018 ONE DAY Fleet Mastery Military Might 12/ 22/2018 12/ 23/2018 Assault Battles Ghosts of Dathomir 12/22/2018 ONE DAY Special Event Rebels and Geonosians 12/24/2018 ONE DAY Omega Battles Ground War 12/24/2018 12/25/ 2018 Assault Battles Grandmaster's Training 12/24/2018 12/25/2018 Mythic Ewoks and Empire 12/25/2018 ONE DAY Omega Battles Military Might 12/ 25/2018 12/ 26/2018 Assault Battles Executrix 12/ 25/ 2018 ONE DAY Fleet Mastery The Artist of War 12/ 25/ 2018 12/ 26/ 2018 Mythic One Famous Wookie 12/25/2018 1/8/2019 Legendary Jedi and Tusken 12/26/2018 ONE DAY Omega Battles Forest Moon 12/26/2018 12/27/2018 Assault Battles Home One 12/26/2018 ONE DAY Fleet Mastery Sith and Droids 12/27/2018 ONE DAY Omega Battles Secrets and Shadows 12/ 27/ 2018 12/ 28/2018 Assault Battles Endurance 12/27/2018 ONE DAY Fleet Mastery Emperor's Demise 12/ 27/ 2018 12/ 28/ 2018 Mythic Nightsisters and Jawas 12/28/2018 ONE DAY Omega Battles Geonosian Fleet Advanced Tactic 12/28/2018 ONE DAY Fleet Mastery Rebel Round-Up 12/28/2018 12/29/2018 Assault Battles Daring Droid 12/ 28/ 2018 12/ 29/ 2018 Mythic Resistance and Clones 12/29/2018 ONE DAY Omega Battles Places of Power 12/ 29/2018 12/ 30/2018 Assault Battles Pieces and Plans 12/29/2018 12/ 30/2018 Mythic First Order and Scoundrels 12/30/2018 ONE DAY Omega Battles Defense of Dathomir 12/31/2018 1/1/2019 Heroic | ITB START DATE Imperial Retaliation 12/3/2018 Territory Battle ‘ Rebel Assault 12/ 13/2018 Territory Battle l Imperial Retaliation 12/ 20/ 2018 Territory Battle TW PREVIEW PHASE War 53-A 12/ 1/ 2018 Territory War War 54-8 12/ 11/ 2018 Territory War | War 55—A 12/ 29/ 2018 Territory War War 56-3 1/ 2/ 2018 Territory War ‘"; RegexOptions options = RegexOptions.Multiline; Regex regex = new Regex(pattern, options); string result = regex.Replace(input, substitution); } }

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx