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
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"<DIV\s*class=\"[^\"]*lesson.*><[aA][^>]*class=large-text[^>]*href\s*=[\*\"|'](.*?)[\*\"|']>((.|\n)*?)<\/[aA]>[.|\n]*<\/DIV|div>") test_str = ("<form action=\"#\" id=\"ModalFormB\" method=\"POST\">\n" " <table>\n" " <colgroup>\n" " <col class=\"nome_riga\">\n" " <col class=\"desc_riga\">\n" " <col class=\"normale\" span=\"<?=$results['colonne']-3?>\">\n" " <col class=\"ultima\">\n" " </colgroup>\n" " <tr class=\"nascosta\">\n" " <th class=\"nome_riga\"></th>\n" " <th class=\"desc_riga\"></th>\n" " <th class=\"normale\" colspan=\"<?=$results['colonne']-3?>\"></th>\n" " <th class=\"ultima\"></th>\n" " </tr>\n" " <tr>\n" " <td colspan=\"<?=$results['colonne']?>\" class=\"verde\">B. Impianti di generazione di energia\n" " (termica, elettrica, cogenerazione, ...)<br> Aggiungere nuove\n" " colonne in caso l'impianto sia dotato di più di 4 generatori.\n" " <input type=\"hidden\" name=\"IdQuestionario\" value=\"<?=$IdQuestionario?>\" />\n" " </td>\n" " </tr>\n\n" " <?=$results['Intestazione']?>\n\n" " <tr class=\"required\">\n" " <td class=\"capolinea\">B0.</td>\n" " <td class=\"grassetto\">Funzione</td>\n" " <?=$results['Funzione']?>\n" " <td>&nbsp;</td>\n" " </tr>\n\n" " <tr class=\"required\">\n" " <td class=\"capolinea\">B1.</td>\n" " <td class=\"grassetto\">Potenza termica nominale</td>\n" " <?=$results['PotenzaTermica']?>\n" " <td class=\"corsivo\">Indicare la potenza termica nominale di ogni\n" " generatore [kW]</td>\n" " </tr>\n\n" " <tr class=\"required\">\n" " <td class=\"capolinea\">B2.</td>\n" " <td class=\"grassetto\">Potenza elettrica nominale</td>\n" " <?=$results['PotenzaElettrica']?>\n" " <td class=\"corsivo\">Indicare la potenza elettrica nominale di ogni\n" " generatore [kW]</td>\n" " </tr>\n\n" " <tr class=\"required\">\n" " <td class=\"capolinea\">B3.</td>\n" " <td class=\"grassetto\">Fonti energetiche utilizzate</td>\n" " <?=$results['Fonti']?>\n" " <td class=\"corsivo\">Indicare per ogni unità di generazione la/le\n" " fonte/fonti utilizzata/e per produzione di energia termica,\n" " rinnovabile o non rinnovabile (in caso di recuperi da processi\n" " industriali, specificare la fonte utilizzata nel processo). Nel caso\n" " di più fonti separare le singole fonti utilizzando il ; (punto e\n" " virgola).\n" " <br>\n" " <b>Indicare una delle seguenti voci: pellet di legno;\n" " cippato di legno; vinacce; gusci; sansa; altra biomassa legnosa;\n" " olio vegetale grezzo; altri bioliquidi; biogas; rifiuti\n" " industriali; rifiuti urbani; energia solare termica; energia\n" " geotermica; carbone; gas naturale; gasolio; altri prodotti\n" " petroliferi; pompa di calore idrotermica; pompa di calore\n" " aerotermica; pompa di calore geotermica. </b></td>\n" " </tr>\n\n" " <tr class=\"required\">\n" " <td class=\"capolinea\" rowspan=\"2\">B4.</td>\n" " <td class=\"grassetto\" rowspan=\"2\">Rendimento di conversione medio\n" " dell'impianto</td>\n" " <?=$results['RendimentoImpianto']?>\n" " <td>&nbsp;</td>\n" " </tr>\n" " <tr class=\"required\">\n" " <?=$results['RendImpCostr']?>\n" " <td>specificare se: dichiarato dal costruttore o dato medio ricavato\n" " in esercizio</td>\n" " </tr>\n\n" " <tr class=\"cogenerazione\">\n" " <td class=\"capolinea\" rowspan=\"2\">B5.</td>\n" " <td class=\"grassetto\" rowspan=\"2\">Rendiemento di conversione medio\n" " dell'impianto che produce elettricità</td>\n" " <?=$results['RendimentoElettrico']?>\n" " <td>&nbsp;</td>\n" " </tr>\n" " <tr class=\"cogenerazione\">\n" " <?=$results['RendElCostr']?>\n" " <td>specificare se: dichiarato dal costruttore o dato medio ricavato\n" " in esercizio</td>\n" " </tr>\n\n" " <tr>\n" " <td class=\"capolinea\">B6.</td>\n" " <td class=\"grassetto\">Sigla generatore</td>\n" " <?=$results['SiglaGeneratore']?>\n" " <td class=\"corsivo\">La sigla del generatore riportata\n" " nell'autorizzazione alle emissioni in atmosfera (rilasciata dalla\n" " Provincia ai sensi del DPR n. 203 del 1988 o del D.Lgs. n. 152 del\n" " 2006), <b>se l'impianto prevede il rilascio di tale autorizzazione</b></td>\n" " </tr>\n\n" " <tr>\n" " <td class=\"capolinea\">B7.</td>\n" " <td class=\"grassetto\">Ore di funzionamento annue</td>\n" " <?=$results['OreAnnue']?>\n" " <td>&nbsp;</td>\n" " </tr>\n\n" " <tr class=\"piccolo medio\">\n" " <td class=\"capolinea\">B8.</td>\n" " <td class=\"grassetto\">Inquinante; emissioni; unità di misura</td>\n" " <?=$results['Inqinanti']?>\n" " <td class=\"corsivo\"><b>ogni impianto soggetto ad autorizzazione alle\n" " emissioni</b> deve fare o un autonomo controllo 1 volta l'anno (si\n" " tratta di certificati analitici: si prega di inviare tali relazioni\n" " in allegato alla presente tabella) o misure in continuo (in questo\n" " caso indicare l'inquinante, le emissioni corrispondenti e l'unità di\n" " misura).</td>\n" " </tr>\n\n" " <tr class=\"piccolo medio\">\n" " <td class=\"capolinea\">B9.</td>\n" " <td class=\"grassetto\">Sistema di abbattimento degli inquinanti</td>\n" " <?=$results['Abbattimento']?>\n\n" " <td class=\"corsivo\">Indicare i sistemi di abbattimento degli\n" " inquinanti installati, eventualmente unendo più celle se più\n" " generatori fanno riferimento ad un unico camino e ad un'unica linea\n" " fumi</td>\n" " </tr>\n" " </table>\n" " <?=$results['bottoni']?>\n" " </form>\n") 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