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

/
/
gis

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"^(?:[[:^print:][:cntrl:]\s]|GIF89.{0,20})*(?:<[^>]+>\s*)+<title>contador\s*de \s*acessos<\/title>.{0,1350}?\$caminho\s*=\s*""contador\.txt.{0,150}?\$arquivo\s*=\s*fopen\(\$caminho.{0,150}?numero\s*de\s*visitas\s*fclose\(\$arquivo.{0,650}?<meta.{0,50}?url=['""]contador\.php.{0,50}?\/html[[:punct:]\s]+$"; string input = @"<html> <head> <title>Contador de Acessos</title> <meta http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1""><style type=""text/css""> <!-- body,td,th { color: #FF0000; font-family: Verdana; font-size: 12px; } body { background-color: #CCCCCC; } .style1 { font-size: 15px; font-weight: bold; } .style2 { font-size: 12px; color: #FF0000; } .style3 { font-size: 15px; color: #000000; } .style4 {color: #000000} .style5 {font-size: 15px; font-weight: bold; color: #000000; } .style8 {font-size: 24px; font-weight: bold; } .style9 {color: #CCCCCC} .style11 {color: #FF0000} .style12 {color: #FFFFFF} .style15 {color: #FFFFFF; font-size: 20px; } --> </style><body link=""#FF0000"" vlink=""#FF0000"" alink=""#FF0000""> <center> <table width=""476"" border=""0""> <tr> <td width=""470"" bgcolor=""#000000""><div align=""center""><span class=""style15""> CONTADOR - <span class=""style11"">BB</span></span> </div></td> </tr> </table> <p><span class=""style5""> $$ CONTADOR DE ACESSOS $$ <br> <br> <span class=""style2"">==========================================================</span><br> </span><br> <span class=""style4"">VOC&Ecirc; POSSUI<span class=""style9"">-</span> </span> </h1> <span class=""style8""> <?php $caminho = ""contador.txt"";//nome do arquivo que vai guardar os visitantes $arquivo = fopen($caminho, ""r"");//abre o arquivo $total = fgets($arquivo,1024); //pega o numero de visitas fclose($arquivo);//fecha o arquivo $x = $total; echo "" . $x;//mostra na tela o numero de visitantes ?> </span> <span class=""style4""> CLIQUES.</span> <br> <br> <br> <br> <span class=""style4""><strong>OBS:</strong> A P&Aacute;GINA FICA ATUALIZANDO AUTOMATICAMENTE EM 60 SEGUNDOS. </span></p> <table width=""568"" border=""0""> <tr> <td bgcolor=""#000000""><div align=""center""><span class=""style12"">CONTADOR SPAM<span class=""style11""></span></span></div></td> </tr> </table> <p><br> </p> <meta http-equiv='Refresh' content='60'; URL='contador.php'> </center> </body> </head> </html>"; RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Singleline; 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