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 = @"<div[\s\S]*?id=\""variationsTwister[\s\S]*?<span[\s\S]*?a-dropdown-container[\s\S]*?<select[\s\S]*?<\/select>[\s\S]*?Color:<\/span>[\s\S]*?<span[\s\S]*?>([\s\S]*?)<\/span>"; string input = @"<div id=""variationsTwister"" class=""a-section a-spacing-mini""> <div class=""a-section a-spacing-micro""> <span class=""a-size-base"">Size:</span> <span class=""a-size-base a-text-bold""></span> </div> <span class=""a-dropdown-container""><select name="" autocomplete=""off"" data-a-native-class=""olpTwisterDropdown"" tabindex=""-1"" class=""a-native-dropdown a-spacing-small olpTwisterDropdown""> <option value=""/gp/offer-listing/B00NNA39IE/ref=olp_twister_all?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=all""> Lowest offer for each </option> <option value=""/gp/offer-listing/B00MC3QSKO/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=0""> 5 M US </option> <option value=""/gp/offer-listing/B00MC3QU1G/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=1""> 5.5 M US </option> <option value=""/gp/offer-listing/B00MC3QX72/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=2""> 6 M US </option> <option value=""/gp/offer-listing/B00MC3QYQC/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=3""> 6.5 M US </option> <option value=""/gp/offer-listing/B00MC3R0PQ/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=4""> 7 M US </option> <option value=""/gp/offer-listing/B00MC3R23Q/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=5""> 7.5 M US </option> <option value=""/gp/offer-listing/B00MC3R3M6/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=6"" selected=""> 8 M US </option> <option value=""/gp/offer-listing/B00MC3R6LO/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=7""> 8.5 M US </option> <option value=""/gp/offer-listing/B00MC3R9IY/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=8""> 9 M US </option> <option value=""/gp/offer-listing/B00MC3RBE6/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=9""> 9.5 M US </option> <option value=""/gp/offer-listing/B00MC3RCPY/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=10""> 10 M US </option> </select><span tabindex=""-1"" id=""olpTwisterDropdownAUI"" class=""a-button a-button-dropdown a-button-small a-spacing-small"" style=""min-width: 0.583333%;""><span class=""a-button-inner""><span class=""a-button-text a-declarative"" data-action=""a-dropdown-button"" role=""button"" tabindex=""0"" aria-hidden=""true""><span class=""a-dropdown-prompt""> 8 M US </span></span><i class=""a-icon a-icon-dropdown""></i></span></span></span> <div class=""a-section a-spacing-micro""> <span class=""a-size-base"">Color:</span> <span class=""a-size-base a-text-bold"">Taupe</span> </div> <ul class=""a-unordered-list a-nostyle a-button-list a-declarative a-button-toggle-group a-horizontal a-spacing-small"" role=""radiogroup"" data-action=""a-button-group""> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-normal a-button-thumbnail a-button-toggle"" id=""a-autoid-0""><span class=""a-button-inner""><a href=""/gp/offer-listing/B0002MB0DM/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=0&amp;mv_size_name=6"" class=""a-button-text"" role=""button"" id=""a-autoid-0-announce""> <img alt="" src=""https://images-na.ssl-images-amazon.com/images/I/41jl1EwZjHL._SX35_SY35_CR,0,0,35,35_.jpg"" height=""35"" width=""35""> </a></span></span> </span></li> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-normal a-button-thumbnail a-button-toggle"" id=""a-autoid-1""><span class=""a-button-inner""><a href=""/gp/offer-listing/B005BFV1DO/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=1&amp;mv_size_name=6"" class=""a-button-text"" role=""button"" id=""a-autoid-1-announce""> <img alt="" src=""https://images-na.ssl-images-amazon.com/images/I/41XqEgaqwtL._SX35_SY35_CR,0,0,35,35_.jpg"" height=""35"" width=""35""> </a></span></span> </span></li> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-normal a-button-thumbnail a-button-toggle"" id=""a-autoid-2""><span class=""a-button-inner""><a href=""/gp/offer-listing/B00MC3SFXW/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=2&amp;mv_size_name=6"" class=""a-button-text"" role=""button"" id=""a-autoid-2-announce""> <img alt="" src=""https://images-na.ssl-images-amazon.com/images/I/41cNhnckTFL._SX35_SY35_CR,0,0,35,35_.jpg"" height=""35"" width=""35""> </a></span></span> </span></li> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-selected a-button-thumbnail a-button-toggle"" id=""a-autoid-3""><span class=""a-button-inner""><a href=""/gp/offer-listing/B00MC3R3M6/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=3&amp;mv_size_name=6"" class=""a-button-text"" role=""button"" id=""a-autoid-3-announce""> <img alt="" src=""https://images-na.ssl-images-amazon.com/images/I/41p2f8xA8TL._SX35_SY35_CR,0,0,35,35_.jpg"" height=""35"" width=""35""> </a></span></span> </span></li> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-normal a-button-thumbnail a-button-toggle"" id=""a-autoid-4""><span class=""a-button-inner""><a href=""/gp/offer-listing/B011SBR9PS/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=4&amp;mv_size_name=6"" class=""a-button-text"" role=""button"" id=""a-autoid-4-announce""> <img alt="" src=""https://images-na.ssl-images-amazon.com/images/I/311Xw94d26L._SX35_SY35_CR,0,0,35,35_.jpg"" height=""35"" width=""35""> </a></span></span> </span></li> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-normal a-button-thumbnail a-button-toggle"" id=""a-autoid-5""><span class=""a-button-inner""><a href=""/gp/offer-listing/B07FYS34S4/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=5&amp;mv_size_name=6"" class=""a-button-text"" role=""button"" id=""a-autoid-5-announce""> <img alt="" src=""https://images-na.ssl-images-amazon.com/images/I/41r4qvtmEkL._SX35_SY35_CR,0,0,35,35_.jpg"" height=""35"" width=""35""> </a></span></span> </span></li> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-normal a-button-thumbnail a-button-toggle"" id=""a-autoid-6""><span class=""a-button-inner""><a href=""/gp/offer-listing/B00MC3TVSK/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=6&amp;mv_size_name=6"" class=""a-button-text"" role=""button"" id=""a-autoid-6-announce""> <img alt="" src=""https://images-na.ssl-images-amazon.com/images/I/31YEDbIcNwL._SX35_SY35_CR,0,0,35,35_.jpg"" height=""35"" width=""35""> </a></span></span> </span></li> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-normal a-button-thumbnail a-button-toggle"" id=""a-autoid-7""><span class=""a-button-inner""><a href=""/gp/offer-listing/B016W1Z1RC/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=7&amp;mv_size_name=6"" class=""a-button-text"" role=""button"" id=""a-autoid-7-announce""> <img alt="" src=""https://images-na.ssl-images-amazon.com/images/I/41plM8TSFBL._SX35_SY35_CR,0,0,35,35_.jpg"" height=""35"" width=""35""> </a></span></span> </span></li> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-normal a-button-thumbnail a-button-toggle"" id=""a-autoid-8""><span class=""a-button-inner""><a href=""/gp/offer-listing/B0007L7WPS/ref=olp_twister_child?ie=UTF8&amp;mv_color_name=8&amp;mv_size_name=6"" class=""a-button-text"" role=""button"" id=""a-autoid-8-announce""> <img alt="" src=""https://images-na.ssl-images-amazon.com/images/I/41NGM8gp7hL._SX35_SY35_CR,0,0,35,35_.jpg"" height=""35"" width=""35""> </a></span></span> </span></li> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-disabled a-button-thumbnail a-button-toggle"" id=""a-autoid-9""><span class=""a-button-inner""><input disabled=""disabled"" class=""a-button-input"" type=""submit"" aria-labelledby=""a-autoid-9-announce""><span class=""a-button-text"" aria-hidden=""true"" id=""a-autoid-9-announce""> <img alt="" src=""https://images-na.ssl-images-amazon.com/images/I/41WBKxWvoLL._SX35_SY35_CR,0,0,35,35_.jpg"" height=""35"" width=""35""> </span></span></span> </span></li> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-disabled a-button-thumbnail a-button-toggle"" id=""a-autoid-10""><span class=""a-button-inner""><input disabled=""disabled"" class=""a-button-input"" type=""submit"" aria-labelledby=""a-autoid-10-announce""><span class=""a-button-text"" aria-hidden=""true"" id=""a-autoid-10-announce""> <img alt="" src=""https://images-na.ssl-images-amazon.com/images/I/41ap6ahxMRL._SX35_SY35_CR,0,0,35,35_.jpg"" height=""35"" width=""35""> </span></span></span> </span></li> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-disabled a-button-thumbnail a-button-toggle"" id=""a-autoid-11""><span class=""a-button-inner""><input disabled=""disabled"" class=""a-button-input"" type=""submit"" aria-labelledby=""a-autoid-11-announce""><span class=""a-button-text"" aria-hidden=""true"" id=""a-autoid-11-announce""> <img alt="" src=""https://images-na.ssl-images-amazon.com/images/I/41QD5K54hPL._SX35_SY35_CR,0,0,35,35_.jpg"" height=""35"" width=""35""> </span></span></span> </span></li> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-disabled a-button-thumbnail a-button-toggle"" id=""a-autoid-12""><span class=""a-button-inner""><input disabled=""disabled"" class=""a-button-input"" type=""submit"" aria-labelledby=""a-autoid-12-announce""><span class=""a-button-text"" aria-hidden=""true"" id=""a-autoid-12-announce""> <img alt="" src=""https://images-na.ssl-images-amazon.com/images/I/31qtQ78OWiL._SX35_SY35_CR,0,0,35,35_.jpg"" height=""35"" width=""35""> </span></span></span> </span></li> <li class=""a-spacing-mini""><span class=""a-list-item""> <span class=""a-button a-button-normal a-button-toggle"" id=""a-autoid-13""><span class=""a-button-inner""><a href=""/gp/offer-listing/B00NNA39IE/ref=olp_twister_all?ie=UTF8&amp;mv_color_name=all&amp;mv_size_name=6"" class=""a-button-text"" role=""button"" id=""a-autoid-13-announce""> Lowest offer for each </a></span></span> </span></li> </ul> </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