Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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
No Match

r'
'
gm

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"ingredient-amount""\>(.+)\<\/span>"; string input = @"<div class=""wprm-recipe-ingredients-container wprm-recipe-ingredients-no-images wprm-recipe-31141-ingredients-container wprm-block-text-normal wprm-ingredient-style-regular wprm-recipe-images-before"" data-recipe=""31141"" data-servings=""16""><h3 class=""wprm-recipe-header wprm-recipe-ingredients-header wprm-block-text-bold wprm-align-left wprm-header-decoration-none"" style="">Ingredients</h3><div class=""wprm-recipe-ingredient-group""><h4 class=""wprm-recipe-group-name wprm-recipe-ingredient-group-name wprm-block-text-bold"">For the dough:</h4><ul class=""wprm-recipe-ingredients""><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""1""><span class=""wprm-recipe-ingredient-amount"">2/3</span>&#32;<span class=""wprm-recipe-ingredient-unit"">cup</span>&#32;<span class=""wprm-recipe-ingredient-name"">heavy cream</span>&#32;<span class=""wprm-recipe-ingredient-notes wprm-recipe-ingredient-notes-faded"">(at room temperature)</span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""2""><span class=""wprm-recipe-ingredient-amount"">1</span>&#32;<span class=""wprm-recipe-ingredient-unit"">cup</span>&#32;<span class=""wprm-recipe-ingredient-name"">milk</span>&#32;<span class=""wprm-recipe-ingredient-notes wprm-recipe-ingredient-notes-faded"">(whole milk preferred, but you can use 2%, at room temperature)</span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""3""><span class=""wprm-recipe-ingredient-amount"">1</span>&#32;<span class=""wprm-recipe-ingredient-name"">large egg</span>&#32;<span class=""wprm-recipe-ingredient-notes wprm-recipe-ingredient-notes-faded"">(at room temperature)</span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""4""><span class=""wprm-recipe-ingredient-amount"">1/3</span>&#32;<span class=""wprm-recipe-ingredient-unit"">cup</span>&#32;<span class=""wprm-recipe-ingredient-name"">sugar</span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""5""><span class=""wprm-recipe-ingredient-amount"">1/2</span>&#32;<span class=""wprm-recipe-ingredient-unit"">cup</span>&#32;<span class=""wprm-recipe-ingredient-name"">cake flour</span>&#32;<span class=""wprm-recipe-ingredient-notes wprm-recipe-ingredient-notes-faded"">(can substitute 1/2 cup all purpose flour sifted with 1 tbsp cornstarch)</span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""6""><span class=""wprm-recipe-ingredient-amount"">3 1/2</span>&#32;<span class=""wprm-recipe-ingredient-unit"">cups</span>&#32;<span class=""wprm-recipe-ingredient-name"">bread flour</span>&#32;<span class=""wprm-recipe-ingredient-notes wprm-recipe-ingredient-notes-faded"">(tap measuring cup to avoid air pockets)</span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""7""><span class=""wprm-recipe-ingredient-amount"">1</span>&#32;<span class=""wprm-recipe-ingredient-unit"">tablespoon</span>&#32;<span class=""wprm-recipe-ingredient-name"">active dry yeast</span>&#32;<span class=""wprm-recipe-ingredient-notes wprm-recipe-ingredient-notes-faded"">(or instant yeast)</span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""8""><span class=""wprm-recipe-ingredient-amount"">1 1/2</span>&#32;<span class=""wprm-recipe-ingredient-unit"">teaspoons</span>&#32;<span class=""wprm-recipe-ingredient-name""><a href=""https://thewoksoflife.com/chinese-spices-condiments/#salt"" class=""wprm-recipe-ingredient-link"" target=""_blank"">salt</a></span></li></ul></div><div class=""wprm-recipe-ingredient-group""><h4 class=""wprm-recipe-group-name wprm-recipe-ingredient-group-name wprm-block-text-bold"">For the filling:</h4><ul class=""wprm-recipe-ingredients""><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""10""><span class=""wprm-recipe-ingredient-amount"">2</span>&#32;<span class=""wprm-recipe-ingredient-unit"">tablespoons</span>&#32;<span class=""wprm-recipe-ingredient-name"">vegetable oil</span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""11""><span class=""wprm-recipe-ingredient-amount"">1/2</span>&#32;<span class=""wprm-recipe-ingredient-unit"">cup</span>&#32;<span class=""wprm-recipe-ingredient-name""><a href=""https://thewoksoflife.com/chinese-chives-scallions-aromatics-peppers/#shallots"" class=""wprm-recipe-ingredient-link"" target=""_blank"">shallots</a></span>&#32;<span class=""wprm-recipe-ingredient-notes wprm-recipe-ingredient-notes-faded"">(or onion, finely chopped)</span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""12""><span class=""wprm-recipe-ingredient-amount"">2</span>&#32;<span class=""wprm-recipe-ingredient-unit"">tablespoons</span>&#32;<span class=""wprm-recipe-ingredient-name"">granulated sugar</span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""13""><span class=""wprm-recipe-ingredient-amount"">2</span>&#32;<span class=""wprm-recipe-ingredient-unit"">teaspoons</span>&#32;<span class=""wprm-recipe-ingredient-name""><a href=""https://thewoksoflife.com/soy-sauce/"" class=""wprm-recipe-ingredient-link"" target=""_blank"">light soy sauce</a></span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""14""><span class=""wprm-recipe-ingredient-amount"">2</span>&#32;<span class=""wprm-recipe-ingredient-unit"">tablespoons</span>&#32;<span class=""wprm-recipe-ingredient-name""><a href=""https://thewoksoflife.com/oyster-sauce/"" class=""wprm-recipe-ingredient-link"" target=""_blank"">oyster sauce</a></span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""15""><span class=""wprm-recipe-ingredient-amount"">1 1/2</span>&#32;<span class=""wprm-recipe-ingredient-unit"">teaspoons</span>&#32;<span class=""wprm-recipe-ingredient-name""><a href=""https://thewoksoflife.com/sesame-oil/"" class=""wprm-recipe-ingredient-link"" target=""_blank"">sesame oil</a></span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""16""><span class=""wprm-recipe-ingredient-amount"">2</span>&#32;<span class=""wprm-recipe-ingredient-unit"">teaspoons</span>&#32;<span class=""wprm-recipe-ingredient-name""><a href=""https://thewoksoflife.com/dark-soy-sauce/"" class=""wprm-recipe-ingredient-link"" target=""_blank"">dark soy sauce</a></span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""17""><span class=""wprm-recipe-ingredient-amount"">¾</span>&#32;<span class=""wprm-recipe-ingredient-unit"">cup</span>&#32;<span class=""wprm-recipe-ingredient-name""><a href=""https://thewoksoflife.com/homemade-chicken-stock/"" class=""wprm-recipe-ingredient-link"" target=""_blank"">chicken stock</a></span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""18""><span class=""wprm-recipe-ingredient-amount"">2</span>&#32;<span class=""wprm-recipe-ingredient-unit"">tablespoons</span>&#32;<span class=""wprm-recipe-ingredient-name"">all purpose flour</span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""19""><span class=""wprm-recipe-ingredient-amount"">2</span>&#32;<span class=""wprm-recipe-ingredient-unit"">cups</span>&#32;<span class=""wprm-recipe-ingredient-name""><a href=""https://thewoksoflife.com/chinese-bbq-pork-cha-siu/"" class=""wprm-recipe-ingredient-link"" target=""_blank"">Chinese roast pork</a></span>&#32;<span class=""wprm-recipe-ingredient-notes wprm-recipe-ingredient-notes-faded"">(<a href=""https://thewoksoflife.com/2014/02/chinese-bbq-pork-cha-siu/"" target=""_blank"">char siu</a>, finely diced)</span></li></ul></div><div class=""wprm-recipe-ingredient-group""><h4 class=""wprm-recipe-group-name wprm-recipe-ingredient-group-name wprm-block-text-bold"">To finish the buns:</h4><ul class=""wprm-recipe-ingredients""><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""21""><span class=""wprm-recipe-ingredient-name"">egg wash</span>&#32;<span class=""wprm-recipe-ingredient-notes wprm-recipe-ingredient-notes-faded"">(1 egg, beaten with 1 tablespoon water) </span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""22""><span class=""wprm-recipe-ingredient-amount"">1</span>&#32;<span class=""wprm-recipe-ingredient-unit"">tablespoon</span>&#32;<span class=""wprm-recipe-ingredient-name""><a href=""https://thewoksoflife.com/sesame-seeds/"" class=""wprm-recipe-ingredient-link"" target=""_blank"">sesame seeds</a></span>&#32;<span class=""wprm-recipe-ingredient-notes wprm-recipe-ingredient-notes-faded"">(optional)</span></li><li class=""wprm-recipe-ingredient"" style=""list-style-type: disc;"" data-uid=""23""><span class=""wprm-recipe-ingredient-amount"">1</span>&#32;<span class=""wprm-recipe-ingredient-unit"">tablespoon</span>&#32;<span class=""wprm-recipe-ingredient-name"">granulated sugar</span>&#32;<span class=""wprm-recipe-ingredient-notes wprm-recipe-ingredient-notes-faded"">(dissolved in 1 tablespoon boiling water)</span></li></ul></div><div class=""wprm-unit-conversion-container wprm-unit-conversion-container-31141 wprm-unit-conversion-container-links wprm-block-text-normal"" data-recipe-unit-system=""1"" style=""><a href=""#"" role=""button"" class=""wprm-unit-conversion wprmpuc-active"" data-system=""1"" data-recipe=""31141"" style="" aria-label=""Change unit system to US Customary"">US Customary</a> - <a href=""#"" role=""button"" class=""wprm-unit-conversion"" data-system=""2"" data-recipe=""31141"" style="" aria-label=""Change unit system to Metric"">Metric</a></div></div>"; 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