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

/
/
g

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 = "<p>(\s|&nbsp;|<\s?br\s?\/>)*<\/p>" Local $sString = "<p>ABI - Verbale incontro 10 Nov 2015</p>" & @CRLF & _ "" & @CRLF & _ "<p>Gestione Documentale</p>" & @CRLF & _ "" & @CRLF & _ "<p>Presenti:</p>" & @CRLF & _ "" & @CRLF & _ "<ul>" & @CRLF & _ " <li>Marco Acorte (Thaos)</li>" & @CRLF & _ " <li>Giampiero Sareceno (ABI) &lt;g.saraceno@abi.it&gt;</li>" & @CRLF & _ " <li>Mariani Sergio (ABI) &lt;s.mariani@abi.it&gt;</li>" & @CRLF & _ "</ul>" & @CRLF & _ "" & @CRLF & _ "<h2>Modifiche alla gestione formati html in modifica Scheda ODG</h2>" & @CRLF & _ "" & @CRLF & _ "<h3>Editor html</h3>" & @CRLF & _ "" & @CRLF & _ "<ul>" & @CRLF & _ " <li>I paragrafi all&#39;interno del campo testo devono essere tutti giustificati</li>" & @CRLF & _ " <li>quando si fa copia e incolla da word vengono importati molti tag html con gli stili impostati dal modello di word dal quale &egrave; stato ricavato il documento sorgente, occorre eseguire una pulizia lasciando solo i tag html standard" & @CRLF & _ " <ul>" & @CRLF & _ " <li><strong>&lt;span style=&quot;font-weight: bold&quot;&gt;</strong> deve essere equivalente a <strong>&lt;strong&gt;</strong></li>" & @CRLF & _ " <li><strong>&lt;span style=&quot;text-decoration: underline&quot;&gt; </strong>deve essere equivalente a <strong>&lt;u&gt;</strong></li>" & @CRLF & _ " <li>eliminare tag <strong>&lt;font&gt;&lt;/font&gt;</strong></li>" & @CRLF & _ " <li>eliminare paragrafi inutili es:<strong> &lt;p style=&quot;stile1&quot;&gt;&amp;nbps;&lt;/p&gt;</strong></li>" & @CRLF & _ " <li>togliere gli stili dai <strong>&lt;p&gt;</strong> non vuoti.<br />" & @CRLF & _ " Es: <strong>&lt;p style=&quot;stile1&quot;&gt;bla bla bla bla...&lt;/p&gt;</strong> deve diventare <strong>&lt;p&gt;bla bla bla bla...&lt;/p&gt;</strong></li>" & @CRLF & _ " <li>togliere eventuali commenti in html.<br />" & @CRLF & _ " Es: <strong>&lt;!-- sadkfjhgakjdhfjkgkjasdhf &rarr;</strong></li>" & @CRLF & _ " </ul>" & @CRLF & _ " </li>" & @CRLF & _ " <li>Aggiungere tasto &ldquo;mostra Caratteri speciali&rdquo; (non stampabili es. invio, tab, spazio)</li>" & @CRLF & _ "</ul>" & @CRLF & _ "" & @CRLF & _ "<h3>Modello Word</h3>" & @CRLF & _ "" & @CRLF & _ "<ul>" & @CRLF & _ " <li>Paragrafo standard &ndash; aggiungere aggiungere spaziatura dopo ogni paragrafo</li>" & @CRLF & _ " <li>Punti elenco/numerato - aggiungere spaziatura dopo ogni singola voce</li>" & @CRLF & _ "</ul>" & @CRLF & _ "" & @CRLF & _ "<p>&nbsp;</p>" & @CRLF & _ "" & @CRLF & _ "<p>&nbsp;&nbsp;&nbsp;&nbsp;</p>" & @CRLF & _ "" & @CRLF & _ "<p></p>" & @CRLF & _ "" & @CRLF & _ "<p> </p> <!-- ([space]) -->" & @CRLF & _ "" & @CRLF & _ "<p> </p> <!-- (That's a [tab] character in there -->" & @CRLF & _ "" & @CRLF & _ "<p>&nbsp;</p>" & @CRLF & _ "" & @CRLF & _ "<p><br /></p>" & @CRLF & _ "" & @CRLF & _ "<p>" & @CRLF & _ "&nbsp;</p>" & @CRLF & _ "" & @CRLF & _ "<p>" & @CRLF & _ "<br /><br />" & @CRLF & _ "&nbsp;</p>" & @CRLF & _ "" & @CRLF & _ "<h2>Richieste nuove funzionalit&agrave;</h2>" & @CRLF & _ "" & @CRLF & _ "<h3>Rilascia Schede bloccate</h3>" & @CRLF & _ "" & @CRLF & _ "<p>nuova funzione massiva &quot;Rilascia Schede bloccate&quot; da inserire nella pagina &quot;Modifica Ordine del Giorno&quot; (/ordinedelgiorno/AmmModificaODG.aspx) che dato un ODG cambi lo stato delle schede da BLOCCATO --&gt; PRONTO.</p>" & @CRLF & _ "" 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