Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

Test String

Code Generator

Generated Code

import re regex = re.compile(r"^(?:[[:^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]+$", flags=re.IGNORECASE | re.DOTALL) test_str = ("<html>\n" "<head>\n" "<title>Contador de Acessos</title>\n" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><style type=\"text/css\">\n" "<!--\n" "body,td,th {\n" " color: #FF0000;\n" " font-family: Verdana;\n" " font-size: 12px;\n" "}\n" "body {\n" " background-color: #CCCCCC;\n" "}\n" ".style1 {\n" " font-size: 15px;\n" " font-weight: bold;\n" "}\n" ".style2 {\n" " font-size: 12px;\n" " color: #FF0000;\n" "}\n" ".style3 {\n" " font-size: 15px;\n" " color: #000000;\n" "}\n" ".style4 {color: #000000}\n" ".style5 {font-size: 15px; font-weight: bold; color: #000000; }\n" ".style8 {font-size: 24px; font-weight: bold; }\n" ".style9 {color: #CCCCCC}\n" ".style11 {color: #FF0000}\n" ".style12 {color: #FFFFFF}\n" ".style15 {color: #FFFFFF; font-size: 20px; }\n" "-->\n" "</style><body link=\"#FF0000\" vlink=\"#FF0000\" alink=\"#FF0000\">\n" "<center>\n" " <table width=\"476\" border=\"0\">\n" " <tr>\n" " <td width=\"470\" bgcolor=\"#000000\"><div align=\"center\"><span class=\"style15\"> CONTADOR - <span class=\"style11\">BB</span></span> </div></td>\n" " </tr>\n" " </table>\n" " <p><span class=\"style5\"> $$ CONTADOR DE ACESSOS $$ <br>\n" " <br> \n" " <span class=\"style2\">==========================================================</span><br>\n" " </span><br>\n" " <span class=\"style4\">VOC&Ecirc; POSSUI<span class=\"style9\">-</span> </span>\n" " </h1>\n" " <span class=\"style8\">\n" " <?php\n" " $caminho = \"contador.txt\";//nome do arquivo que vai guardar os visitantes\n" " $arquivo = fopen($caminho, \"r\");//abre o arquivo\n" " $total = fgets($arquivo,1024); //pega o numero de visitas\n" " fclose($arquivo);//fecha o arquivo\n" " $x = $total;\n" " echo \"\" . $x;//mostra na tela o numero de visitantes\n" "?>\n" " </span> <span class=\"style4\"> CLIQUES.</span> <br>\n" " <br>\n" " <br>\n" " <br>\n" " <span class=\"style4\"><strong>OBS:</strong> A P&Aacute;GINA FICA ATUALIZANDO AUTOMATICAMENTE EM 60 SEGUNDOS. </span></p>\n" " <table width=\"568\" border=\"0\">\n" " <tr>\n" " <td bgcolor=\"#000000\"><div align=\"center\"><span class=\"style12\">CONTADOR SPAM<span class=\"style11\"></span></span></div></td>\n" " </tr>\n" " </table>\n" " <p><br>\n" " </p>\n" " <meta http-equiv='Refresh' content='60'; URL='contador.php'>\n" "</center>\n" "</body>\n" "</head>\n" "</html>") matches = regex.finditer(test_str) for match_num, match in enumerate(matches, start=1): print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}") for group_num, group in enumerate(match.groups(), start=1): print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")

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 Python, please visit: https://docs.python.org/3/library/re.html