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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @/ 3Dcache*:().*%252B /; string input = @"<li class=""g""><h3 class=""r""><a href=""http://maps.google.com/maps?um=1&amp;ie=UTF-8&amp;fb=1&amp;gl=us&amp;cid=12546501552342514458&amp;q=Malheur+National+Forest&amp;sa=X&amp;ei=tsCpU7y-HM28oQSa9IIQ&amp;ved=0CBUQtQMwAA""><div>Map for <b>Malheur National Forest</b></div></a></h3><div class=""mlmcm"" style=""margin:16px 0""><a href=""http://maps.google.com/maps?um=1&amp;ie=UTF-8&amp;fb=1&amp;gl=us&amp;cid=12546501552342514458&amp;q=Malheur+National+Forest&amp;sa=X&amp;ei=tsCpU7y-HM28oQSa9IIQ&amp;ved=0CBYQtgMwAA""><img height=""233"" src=""/maps/vt/data=VLHX1wd2Cgu8wR6jwyh-km8JBWAkEzU4,6YhdV0BKWTh3M22uoHrEdeI_eUVZLHdlKYEtPFQ8P__WuSea3AFMDTBKDIzC2UNN2GnK4eVSnL54ZIUZDihddu9CI74my1jHESqjX7czgrXEHjDCIHFYymlYhBU"" style=""border:0;padding:1px"" width=""550""/></a></div><h3 class=""r""><a href=""/url?q=http://www.fs.usda.gov/malheur&amp;sa=U&amp;ei=tsCpU7y-HM28oQSa9IIQ&amp;ved=0CBgQFjAA&amp;usg=AFQjCNEd9QcHqk_lxZTz9AcslMsyLwA9XQ""><b>Malheur National Forest</b> - Home - USDA Forest Service</a></h3><div class=""s""><div class=""kv"" style=""margin-bottom:2px""><cite>www.fs.usda.gov/<b>malheur</b></cite><div class=""am-dwn-arw-container"">‎<div aria-expanded=""false"" aria-haspopup=""true"" data-ved=""0CBkQ7B0wAA"" onclick=""google.sham(this);"" style=""display:inline"" tabindex=""0""><span class=""am-dwn-arw""></span></div><div class=""am-dropdown-menu"" role=""menu"" style=""display:none"" tabindex=""-1""><ul><li class=""am-dropdown-menu-item""><a class=""am-dropdown-menu-item-text"" href=""/url?q=http://webcache.googleusercontent.com/search%3Fq%3Dcache:0bqZkM4XQqIJ:http://www.fs.usda.gov/malheur%252BMalheur%2BNational%2BForest%26hl%3Den%26%26ct%3Dclnk&amp;sa=U&amp;ei=tsCpU7y-HM28oQSa9IIQ&amp;ved=0CBsQIDAA&amp;usg=AFQjCNHcxq8MhoHz9__jp8pwHUrw2RPqCQ"">Cached</a></li><li class=""am-dropdown-menu-item""><a class=""am-dropdown-menu-item-text"" href=""/search?ie=UTF-8&amp;q=related:www.fs.usda.gov/malheur+Malheur+National+Forest&amp;tbo=1&amp;sa=X&amp;ei=tsCpU7y-HM28oQSa9IIQ&amp;ved=0CBwQHzAA"">Similar</a></li></ul></div></div></div><span class=""st"">The 1.7 million acre <b>Malheur National</b> For est is located in the Blue Mountains of <br> Eastern Oregon. The diverse and beautiful scenery of the <b>forest</b> includes high ...</br></span><br><div style=""margin-top:13px""><table width=""100%""><tr><td style=""padding-right:4px;padding-top:1px"" valign=""top"" width=""24""><img src=""/mapfiles/marker-noalpha.png""/></td><td valign=""top"" width=""485""><span style=""vertical-align:top"">Canyon City, OR 97820<br style=""display:block""><span class=""nobr"">(541) 575-3000</span></br></span></td><td style=""padding-top:2px;padding-left:9px"" valign=""top""><div style=""float:right""><div class=""star"" style=""float:none""><div style=""width:0px""> </div></div></div><div style=""clear:both""><a class=""fl nobr"" href=""/url?q=https://plus.google.com/105110280666932757061/about%3Fhl%3Den%26socfid%3Dweb:lu:unknown:localdetails%26socpid%3D1&amp;sa=U&amp;ei=tsCpU7y-HM28oQSa9IIQ&amp;ved=0CCAQ4gkwAA&amp;usg=AFQjCNEo8ifBqVIqKICfCb2t4c6TZYk5mA"">2 reviews</a></div></td></tr></table></div></br></div><table cellpadding=""0"" cellspacing=""0"" class=""slk"" style=""border-collapse:collapse;margin-top:1px""><tr class=""mslg""><td style=""padding-left:23px;vertical-align:top""><div class=""sld""><h3 class=""r""><a class=""sla"" href=""/url?q=http://www.fs.usda.gov/contactus/malheur/about-forest/contactus&amp;sa=U&amp;ei=tsCpU7y-HM28oQSa9IIQ&amp;ved=0CCMQjBAwAQ&amp;usg=AFQjCNGjoBzfmSfSTCOzBNxBnOhKa28FUQ"">Contact Us</a></h3><div class=""s st"" style=""width:220px;overflow:hidden"">More information is available on individual Ranger District Office ...</div></div></td><td style=""padding-left:7px;vertical-align:top""><div class=""sld""><h3 class=""r""><a class=""sla"" href=""/url?q=http://www.fs.usda.gov/recmain/malheur/recreation&amp;sa=U&amp;ei=tsCpU7y-HM28oQSa9IIQ&amp;ved=0CCUQjBAwAw&amp;usg=AFQjCNEmTooI03G5kMNTyIVqgU8Cu822dg"">Recreation</a></h3><div class=""s st"" style=""width:220px;overflow:hidden"">The 1.7 million acre Malheur National Forest located in the ...</div></div></td></tr><tr class=""mslg""><td style=""padding-left:23px;vertical-align:top""><div class=""sld""><h3 class=""r""><a class=""sla"" href=""/url?q=http://www.fs.usda.gov/main/malheur/maps-pubs&amp;sa=U&amp;ei=tsCpU7y-HM28oQSa9IIQ&amp;ved=0CCcQjBAwAg&amp;usg=AFQjCNFuRB8FTFH1goZ5XStBRakys6JoIQ"">Maps &amp; Publications</a></h3><div class=""s st"" style=""width:220px;overflow:hidden"">Forest Service Topography Maps: These maps overlay Forest ...</div></div></td><td style=""padding-left:7px;vertical-align:top""><div class=""sld""><h3 class=""r""><a class=""sla"" href=""/url?q=http://www.fs.usda.gov/main/malheur/about-forest&amp;sa=U&amp;ei=tsCpU7y-HM28oQSa9IIQ&amp;ved=0CCkQjBAwBA&amp;usg=AFQjCNHSrG5pziXkX2tf50PdNo7qWMeT1A"">About the Forest</a></h3><div class=""s st"" style=""width:220px;overflow:hidden"">The Malheur National Forest in the Blue Mountains of Eastern ...</div></div></td></tr><tr><td colspan=""2"" style=""padding-left:28px;vertical-align:top""><div style=""padding-top:5px""><a class=""fl"" href=""/search?ie=UTF-8&amp;q=+site:usda.gov+Malheur+National+Forest&amp;sa=X&amp;ei=tsCpU7y-HM28oQSa9IIQ&amp;ved=0CCoQrAM"">More results from usda.gov »</a></div></td></tr></table></li>"; Match m = Regex.Match(input, pattern); 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