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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "(^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]*)(?=\".*$)"; final String string = "Microsoft Visual Studio Solution File, Format Version 12.00\n" + "# Visual Studio 14\n" + "VisualStudioVersion = 14.0.25420.1\n" + "MinimumVisualStudioVersion = 10.0.40219.1\n" + "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}\"\n" + "EndProject\n" + "Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"CCH.WFM.ServiceTest\", \"Source\\Common\\Tests\\Unit Tests\\ServiceTest\\CCH.WFM.ServiceTest.csproj\", \"{94E3C16B-DFBA-403A-95F9-37FAB7AB88ED}\"\n" + "EndProject\n" + "Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"TestFramework\", \"..\\test\\TestFramework\\TestFramework.csproj\", \"{3F56B03C-0883-4705-91BA-0979CAF6E719}\"\n" + "EndProject\n" + "Global\n" + " GlobalSection(SolutionConfigurationPlatforms) = preSolution\n" + " Debug|Any CPU = Debug|Any CPU\n" + " Release|Any CPU = Release|Any CPU\n" + " EndGlobalSection\n" + " GlobalSection(ProjectConfigurationPlatforms) = postSolution\n" + " {044E36A5-189E-45B1-9753-397BC8ACD31A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\n" + " {044E36A5-189E-45B1-9753-397BC8ACD31A}.Debug|Any CPU.Build.0 = Debug|Any CPU\n" + " {044E36A5-189E-45B1-9753-397BC8ACD31A}.Release|Any CPU.ActiveCfg = Release|Any CPU\n" + " {044E36A5-189E-45B1-9753-397BC8ACD31A}.Release|Any CPU.Build.0 = Release|Any CPU\n" + " {94E3C16B-DFBA-403A-95F9-37FAB7AB88ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\n" + " {94E3C16B-DFBA-403A-95F9-37FAB7AB88ED}.Debug|Any CPU.Build.0 = Debug|Any CPU\n" + " {94E3C16B-DFBA-403A-95F9-37FAB7AB88ED}.Release|Any CPU.ActiveCfg = Release|Any CPU\n" + " {94E3C16B-DFBA-403A-95F9-37FAB7AB88ED}.Release|Any CPU.Build.0 = Release|Any CPU\n" + " {3F56B03C-0883-4705-91BA-0979CAF6E719}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\n" + " {3F56B03C-0883-4705-91BA-0979CAF6E719}.Debug|Any CPU.Build.0 = Debug|Any CPU\n" + " {3F56B03C-0883-4705-91BA-0979CAF6E719}.Release|Any CPU.ActiveCfg = Release|Any CPU\n" + " {3F56B03C-0883-4705-91BA-0979CAF6E719}.Release|Any CPU.Build.0 = Release|Any CPU\n" + " EndGlobalSection\n" + " GlobalSection(SolutionProperties) = preSolution\n" + " HideSolutionNode = FALSE\n" + " EndGlobalSection\n" + " GlobalSection(TeamFoundationVersionControl) = preSolution\n" + " SccNumberOfProjects = 4\n" + " SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}\n" + " SccTeamFoundationServer = https://tfs2013.prosystemfx.com/tfs/nextgen\n" + " SccLocalPath0 = .\n" + " SccProjectUniqueName1 = Source\\\\Common\\\\Tests\\\\Unit\\u0020Tests\\\\WFMTestFramework\\\\CCH.WFM.UnitTest.Framework.csproj\n" + " SccProjectName1 = Source/Common/Tests/Unit\\u0020Tests/WFMTestFramework\n" + " SccLocalPath1 = Source\\\\Common\\\\Tests\\\\Unit\\u0020Tests\\\\WFMTestFramework\n" + " SccProjectUniqueName2 = Source\\\\Common\\\\Tests\\\\Unit\\u0020Tests\\\\ServiceTest\\\\CCH.WFM.ServiceTest.csproj\n" + " SccProjectName2 = Source/Common/Tests/Unit\\u0020Tests/ServiceTest\n" + " SccLocalPath2 = Source\\\\Common\\\\Tests\\\\Unit\\u0020Tests\\\\ServiceTest\n" + " SccProjectUniqueName3 = ..\\\\test\\\\TestFramework\\\\TestFramework.csproj\n" + " SccProjectName3 = ../test/TestFramework\n" + " SccLocalPath3 = ..\\\\test\\\\TestFramework\n" + " EndGlobalSection\n" + "EndGlobal\n"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html