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

/
/

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(<h5\>Atores<\/h5\>\s*)"; string input = @"<div id=""left-stack""> <div parental-rating=""1"" rating-movie=""200,br-movie"" class=""lockup product movie video""> <a href=""https://itunes.apple.com/br/movie/alem-da-escuridao-star-trek/id643978126""> <div class=""artwork""> <img width=""151"" height=""227"" alt=""Além da Escuridão: (Star Trek Into Darkness)"" src-swap-high-dpi=""http://a5.mzstatic.com/us/r30/Video69/v4/6a/7e/3a/6a7e3afe-fa95-e281-84e6-51c532b5b425/poster454x454.jpeg"" src-load-auto-after-dom-load="" src-swap=""http://a4.mzstatic.com/us/r30/Video69/v4/6a/7e/3a/6a7e3afe-fa95-e281-84e6-51c532b5b425/poster227x227.jpeg"" class=""artwork"" src=""https://s.mzstatic.com/htmlResources/3953/frameworks/images/p.png"" /> <meta itemprop=""image"" content=""http://a4.mzstatic.com/us/r30/Video69/v4/6a/7e/3a/6a7e3afe-fa95-e281-84e6-51c532b5b425/poster227x227.jpeg""></meta></div></a> <a onclick=""return its.detect.openItunes(&#39;https://itunes.apple.com/br/movie/alem-da-escuridao-star-trek/id643978126&#39;);"" href=""#"" class=""action view-in-itunes""><span>Ver no iTunes</span></a> <ul class=""list""> <li><span itemscope itemtype=""http://schema.org/Offer"" itemprop=""offers"" class=""price""><span itemprop=""price"" content=""USD 19.99"">USD 19.99</span></span></li> <li class=""genre""><span class=""label"">Gênero: </span><a href=""https://itunes.apple.com/br/genre/filmes-ficcao-cientifica-e/id4413""> <span itemprop=""genre"">Ficção científica e fantasia</span></a></li> <li class=""release-date""><span class=""label"">Lançado: </span><span itemprop=""dateCreated"" content="" 17/05/2013"">2013</span></li><li class=""copyright"">© 2013 Paramount Pictures Corporation. All Rights Reserved.</li></ul> </div>"; 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