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

#include <StringConstants.au3> ; to declare the Constants of StringRegExp #include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate Local $sRegex = "(?is)^(?:[[:^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]+$" Local $sString = "<html>" & @CRLF & _ "<head>" & @CRLF & _ "<title>Contador de Acessos</title>" & @CRLF & _ "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">" & @CRLF & _ "<!--" & @CRLF & _ "body,td,th {" & @CRLF & _ " color: #FF0000;" & @CRLF & _ " font-family: Verdana;" & @CRLF & _ " font-size: 12px;" & @CRLF & _ "}" & @CRLF & _ "body {" & @CRLF & _ " background-color: #CCCCCC;" & @CRLF & _ "}" & @CRLF & _ ".style1 {" & @CRLF & _ " font-size: 15px;" & @CRLF & _ " font-weight: bold;" & @CRLF & _ "}" & @CRLF & _ ".style2 {" & @CRLF & _ " font-size: 12px;" & @CRLF & _ " color: #FF0000;" & @CRLF & _ "}" & @CRLF & _ ".style3 {" & @CRLF & _ " font-size: 15px;" & @CRLF & _ " color: #000000;" & @CRLF & _ "}" & @CRLF & _ ".style4 {color: #000000}" & @CRLF & _ ".style5 {font-size: 15px; font-weight: bold; color: #000000; }" & @CRLF & _ ".style8 {font-size: 24px; font-weight: bold; }" & @CRLF & _ ".style9 {color: #CCCCCC}" & @CRLF & _ ".style11 {color: #FF0000}" & @CRLF & _ ".style12 {color: #FFFFFF}" & @CRLF & _ ".style15 {color: #FFFFFF; font-size: 20px; }" & @CRLF & _ "-->" & @CRLF & _ "</style><body link="#FF0000" vlink="#FF0000" alink="#FF0000">" & @CRLF & _ "<center>" & @CRLF & _ " <table width="476" border="0">" & @CRLF & _ " <tr>" & @CRLF & _ " <td width="470" bgcolor="#000000"><div align="center"><span class="style15"> CONTADOR - <span class="style11">BB</span></span> </div></td>" & @CRLF & _ " </tr>" & @CRLF & _ " </table>" & @CRLF & _ " <p><span class="style5"> $$ CONTADOR DE ACESSOS $$ <br>" & @CRLF & _ " <br> " & @CRLF & _ " <span class="style2">==========================================================</span><br>" & @CRLF & _ " </span><br>" & @CRLF & _ " <span class="style4">VOC&Ecirc; POSSUI<span class="style9">-</span> </span>" & @CRLF & _ " </h1>" & @CRLF & _ " <span class="style8">" & @CRLF & _ " <?php" & @CRLF & _ " $caminho = "contador.txt";//nome do arquivo que vai guardar os visitantes" & @CRLF & _ " $arquivo = fopen($caminho, "r");//abre o arquivo" & @CRLF & _ " $total = fgets($arquivo,1024); //pega o numero de visitas" & @CRLF & _ " fclose($arquivo);//fecha o arquivo" & @CRLF & _ " $x = $total;" & @CRLF & _ " echo "" . $x;//mostra na tela o numero de visitantes" & @CRLF & _ "?>" & @CRLF & _ " </span> <span class="style4"> CLIQUES.</span> <br>" & @CRLF & _ " <br>" & @CRLF & _ " <br>" & @CRLF & _ " <br>" & @CRLF & _ " <span class="style4"><strong>OBS:</strong> A P&Aacute;GINA FICA ATUALIZANDO AUTOMATICAMENTE EM 60 SEGUNDOS. </span></p>" & @CRLF & _ " <table width="568" border="0">" & @CRLF & _ " <tr>" & @CRLF & _ " <td bgcolor="#000000"><div align="center"><span class="style12">CONTADOR SPAM<span class="style11"></span></span></div></td>" & @CRLF & _ " </tr>" & @CRLF & _ " </table>" & @CRLF & _ " <p><br>" & @CRLF & _ " </p>" & @CRLF & _ " <meta http-equiv='Refresh' content='60'; URL='contador.php'>" & @CRLF & _ "</center>" & @CRLF & _ "</body>" & @CRLF & _ "</head>" & @CRLF & _ "</html>" Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH) Local $aFullArray[0] For $i = 0 To UBound($aArray) -1 _ArrayConcatenate($aFullArray, $aArray[$i]) Next $aArray = $aFullArray ; Present the entire match result _ArrayDisplay($aArray, "Result")

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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm