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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @/ (?:[A-Za-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|""(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*"")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]) /; string input = @"David Hills Primeresllc@gmail.com · Reply · 42w Adrian Chu badge icon adrian@adrianchu.net · Reply · 42w Nick Bagoshvili badge icon Nick@ngbroofing.com · Reply · 42w Grace Wang grace@ClarityPropertiesLLC.com · Reply · 42w Pete Venturo That's my neighbor. · Reply · 42w Hom Teang mrteang@gmail.com · Reply · 42w Derek Stephens derek@summitreiholdings.com · Reply · 42w Julie K Clark Julie@seattleinvestorsclub.com · Reply · 42w Alex Frankov alexfrankov@hotmail.com · Reply · 42w Dawn Armstrong Dawnarmstrong&hotmail.com Outlook – free personal email and calendar from Microsoft OUTLOOK.LIVE.COM Outlook – free personal email and calendar from Microsoft Outlook – free personal email and calendar from Microsoft · Reply · 42w Andrey Gulyy Andreygulyyre@gmail.com please · Reply · 42w Viktor Bondarenko viktor76@outlook.com · Reply · 42w Jeremy Macconnell Sendmeyourdeals@foursqre.com · Reply · 42w A Suraphong Liengboonlertchai Abuysellproperty@gmail.com. Thx 🙏 · Reply · 42w Kellen Giroux info@upraisedproperties.com · Reply · 42w Anthony Markiie Prado Amprado@kw.com · Reply · 42w Jamil Newman Westshoreinvestmentgroup@gmail.com · Reply · 42w Joe Clark Josephclark10@gmail.com · Reply · 42w Nick Taitano It's a great opportunity! · Reply · 41w Miao Jiang mj@everestinvestments.net · Reply · 41w AJ Sheffield aj@theoffmarketdeals.com · Reply · 41w Cindy Highsmith Flyfreelw@gmail.com · Reply · 41w Steven Wang stevenwproperties@gmail.com · Reply · 41w Miao Jiang mj@everestinvestments.net · Reply · 40w Les Dreeson ldreeson@listings.com "; RegexOptions options = RegexOptions.Multiline; foreach (Match m in Regex.Matches(input, pattern, options)) { Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); } } }

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