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

/
/
gmi

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(^Project\(""{[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}}""\)\s*=\s*""[\w\d-.]*""\s*,\s*"")\K([\w\d-.\\\s]*)(?="".*$)"; string input = @"Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""CCH.WFM.UnitTest.Framework"", ""Source\Common\Tests\Unit Tests\WFMTestFramework\CCH.WFM.UnitTest.Framework.csproj"", ""{044E36A5-189E-45B1-9753-397BC8ACD31A}"" EndProject Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""CCH.WFM.ServiceTest"", ""Source\Common\Tests\Unit Tests\ServiceTest\CCH.WFM.ServiceTest.csproj"", ""{94E3C16B-DFBA-403A-95F9-37FAB7AB88ED}"" EndProject Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""TestFramework"", ""..\test\TestFramework\TestFramework.csproj"", ""{3F56B03C-0883-4705-91BA-0979CAF6E719}"" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {044E36A5-189E-45B1-9753-397BC8ACD31A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {044E36A5-189E-45B1-9753-397BC8ACD31A}.Debug|Any CPU.Build.0 = Debug|Any CPU {044E36A5-189E-45B1-9753-397BC8ACD31A}.Release|Any CPU.ActiveCfg = Release|Any CPU {044E36A5-189E-45B1-9753-397BC8ACD31A}.Release|Any CPU.Build.0 = Release|Any CPU {94E3C16B-DFBA-403A-95F9-37FAB7AB88ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {94E3C16B-DFBA-403A-95F9-37FAB7AB88ED}.Debug|Any CPU.Build.0 = Debug|Any CPU {94E3C16B-DFBA-403A-95F9-37FAB7AB88ED}.Release|Any CPU.ActiveCfg = Release|Any CPU {94E3C16B-DFBA-403A-95F9-37FAB7AB88ED}.Release|Any CPU.Build.0 = Release|Any CPU {3F56B03C-0883-4705-91BA-0979CAF6E719}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3F56B03C-0883-4705-91BA-0979CAF6E719}.Debug|Any CPU.Build.0 = Debug|Any CPU {3F56B03C-0883-4705-91BA-0979CAF6E719}.Release|Any CPU.ActiveCfg = Release|Any CPU {3F56B03C-0883-4705-91BA-0979CAF6E719}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(TeamFoundationVersionControl) = preSolution SccNumberOfProjects = 4 SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} SccTeamFoundationServer = https://tfs2013.prosystemfx.com/tfs/nextgen SccLocalPath0 = . SccProjectUniqueName1 = Source\\Common\\Tests\\Unit\u0020Tests\\WFMTestFramework\\CCH.WFM.UnitTest.Framework.csproj SccProjectName1 = Source/Common/Tests/Unit\u0020Tests/WFMTestFramework SccLocalPath1 = Source\\Common\\Tests\\Unit\u0020Tests\\WFMTestFramework SccProjectUniqueName2 = Source\\Common\\Tests\\Unit\u0020Tests\\ServiceTest\\CCH.WFM.ServiceTest.csproj SccProjectName2 = Source/Common/Tests/Unit\u0020Tests/ServiceTest SccLocalPath2 = Source\\Common\\Tests\\Unit\u0020Tests\\ServiceTest SccProjectUniqueName3 = ..\\test\\TestFramework\\TestFramework.csproj SccProjectName3 = ../test/TestFramework SccLocalPath3 = ..\\test\\TestFramework EndGlobalSection EndGlobal "; RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase; 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