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

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"calypso:calypsoObject.{10,150}xsi:type=""calypso:(\w{2,50})"; string input = @"<calypso:calypsoDocument xmlns:datauploader=""http://www.calypso.com/datauploader"" xmlns:ftp=""http://www.calypso.com/ftp"" xmlns:liquidityrule=""http://www.calypso.com/liquidityrule"" xmlns:bloomberg=""http://www.calypso.com/bloomberg"" xmlns:liquiditycriteria=""http://www.calypso.com/liquiditycriteria"" xmlns:pricingscript=""http://www.calypso.com/pricingscript"" xmlns:am=""http://www.calypso.com/am"" xmlns:liquidityposition=""http://www.calypso.com/liquidityposition"" xmlns:scriptableOTC=""http://www.calypso.com/scriptableOTC"" xmlns:pricingsheet=""http://www.calypso.com/pricingsheet"" xmlns:matching=""http://www.calypso.com/matching"" xmlns:scheduler=""http://www.calypso.com/scheduler"" xmlns:ns20=""http://www.calypso.com/HedgeAccounting"" xmlns:liquidityreporting=""http://www.calypso.com/liquidityreporting"" xmlns:taskstation=""http://www.calypso.com/taskstation"" xmlns:kpiservice=""http://www.calypso.com/kpiservice"" xmlns:liquiditycore=""http://www.calypso.com/liquiditycore"" xmlns:calypso=""http://www.calypso.com/xml"" xmlns:assumption=""http://www.calypso.com/assumption"" xmlns:liquidityclassification=""http://www.calypso.com/liquidityclassification"" xmlns:collateral=""http://www.calypso.com/collateral"" xmlns:calculationserver=""http://www.calypso.com/calculationserver"" xmlns:bondexoticnote=""http://www.calypso.com/bondexoticnote""><calypso:calypsoObject xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:type=""calypso:FutureCommodity"" version=""14-0"" action=""SAVE""><calypso:identification><calypso:versionedIdentifier version=""0"" code=""21866845"" codifier=""CPSLIVE""/></calypso:identification><calypso:definition><calypso:contract><calypso:type>com.calypso.tk.product.FutureContract</calypso:type><calypso:separator>#</calypso:separator><calypso:identifier code=""USD#LME#LMEZinc"" codifier=""convention""/><calypso:calypsoBusinessKey><calypso:propertyName>currency</calypso:propertyName><calypso:propertyValue>USD</calypso:propertyValue></calypso:calypsoBusinessKey><calypso:calypsoBusinessKey><calypso:propertyName>exchange</calypso:propertyName><calypso:propertyValue>LME</calypso:propertyValue></calypso:calypsoBusinessKey><calypso:calypsoBusinessKey><calypso:propertyName>name</calypso:propertyName><calypso:propertyValue>LMEZinc</calypso:propertyValue></calypso:calypsoBusinessKey></calypso:contract><calypso:expirationDate>2023-10-30Z</calypso:expirationDate><calypso:firstDeliveryDate>2023-10-30Z</calypso:firstDeliveryDate><calypso:firstNotificationDate>2023-10-30Z</calypso:firstNotificationDate><calypso:lastDeliveryDate>2023-10-30Z</calypso:lastDeliveryDate><calypso:lastNotificationDate>2023-10-30Z</calypso:lastNotificationDate><calypso:tradingEndDate>2023-10-30Z</calypso:tradingEndDate><calypso:tradingStartDate>2023-10-30Z</calypso:tradingStartDate><calypso:ccpDate>2023-10-30Z</calypso:ccpDate></calypso:definition></calypso:calypsoObject></calypso:calypsoDocument>"; 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