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

~
~
misUg

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 = "(?misU)<([^<\/>]*)([^<\/>]*)>([\s]*?|(?R))<\/\1>" Local $sString = " <table>" & @CRLF & _ " <tr>" & @CRLF & _ " <th>Nome da Opção</th>" & @CRLF & _ " <th class="boxToolTip" title="O símbolo para PETRD197 Ex:19,7 é PETRD197">Código da Opção</th>" & @CRLF & _ " <th class="boxToolTip" title="PETRD197 Ex:19,7 está listado(a) no mercado Bovespa">Bolsa de Valores</th>" & @CRLF & _ " <th class="boxToolTip" title="">Tipo de Ativo</th>" & @CRLF & _ " " & @CRLF & _ " <th class="boxToolTip" title="O código ISIN para PETRD197 Ex:19,7">Código ISIN do Ativo</th>" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " <th class="ColumnLast">Descrição da Opção</th>" & @CRLF & _ " " & @CRLF & _ " </tr>" & @CRLF & _ " <tr class="odd">" & @CRLF & _ " <td align="center"><b>PETRD197 Ex:19,7 20/04/2020</b></td>" & @CRLF & _ " <td align="center"><b>PETRD197</b></td>" & @CRLF & _ " <td align="center"><b><a href='/bolsa-de-valores/bovespa' title='Bovespa'>Bovespa</a></b></td>" & @CRLF & _ " <td align="center"><span id="quoteElementPiece5" class="">Opção</span></td>" & @CRLF & _ " " & @CRLF & _ " <td align="center"><span id="quoteElementPiece6" class="">BRPETR4D0UU5</span></td>" & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " " & @CRLF & _ " <td align="center">Opção de Compra Ex:19,7 Vencimento: Abril</td>" & @CRLF & _ " " & @CRLF & _ " </tr>" & @CRLF & _ " </table>" & @CRLF & _ "</div>" & @CRLF & _ "" & @CRLF & _ " <div class="TableElement">" & @CRLF & _ " <table>" & @CRLF & _ " <tr>" & @CRLF & _ " <th>Preço de Exercício (Strike)</th>" & @CRLF & _ " <th>Vencimento do Contrato</th>" & @CRLF & _ " <th>Dias até Vencimento</th>" & @CRLF & _ " <th>Tipo de Negócio</th>" & @CRLF & _ " <th>Estilo de Opção</th>" & @CRLF & _ " <th>Classif.</th>" & @CRLF & _ " <th>Valor Intrínsico da Opção</th>" & @CRLF & _ " <th class="ColumnLast">Valor Extrínsico da Opção</th>" & @CRLF & _ " </tr>" & @CRLF & _ " <tr class="odd">" & @CRLF & _ " <td align="center">19,70</td>" & @CRLF & _ " <td align="center">20/04/2020</td>" & @CRLF & _ " <td align="center">3 dias</td>" & @CRLF & _ " <td align="center">Call</td>" & @CRLF & _ " <td align="center">Americano</td>" & @CRLF & _ " <td align="center">OTM</td>" & @CRLF & _ " <td align="center">-3,59</td>" & @CRLF & _ " <td align="center">3,60</td>" & @CRLF & _ " </tr>" & @CRLF & _ " </table>" & @CRLF & _ " </div>" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "<div class="TableElement">" & @CRLF & _ " <table>" & @CRLF & _ " <tr>" & @CRLF & _ " <th class="boxToolTip" title="O preço para PETRD197 Ex:19,7 está em alta ou baixa?">&nbsp;</th>" & @CRLF & _ " <th class="boxToolTip" title="Mudança no preço de PETRD197 Ex:19,7">Variação do Dia (p)</th>" & @CRLF & _ " <th class="boxToolTip" title="Variação no preço de PETRD197 Ex:19,7">Variação do Dia %</th>" & @CRLF & _ " <th class="boxToolTip" title="Preço atual de PETRD197 Ex:19,7">Último Preço</th>" & @CRLF & _ " <th class="boxToolTip" title="Menor preço para as ações de PETRD197 Ex:19,7 hoje">Preço Mínimo</th>" & @CRLF & _ " <th class="boxToolTip" title="Maior preço para as ações de PETRD197 Ex:19,7 hoje">Preço Máximo</th>" & @CRLF & _ " <th class="boxToolTip" title="Preço de abertura para PETRD197 Ex:19,7 hoje">Preço de Abertura</th>" & @CRLF & _ " <th class="boxToolTip" title="Preco de fechamento de PETRD197 Ex:19,7 ontem">Preço de Fechamento</th>" & @CRLF & _ " <th class="boxToolTip" class="ColumnLast" title="Último negócio para PETRD197 Ex:19,7">Hora <img title='' alt='' class='quotePageRTupgradeLink' href='#quotePageRTupgradeContainer' id='cautionImageEnt' src='/common/images/icons/caution_sign.gif'/></th>" & @CRLF & _ " </tr>" & @CRLF & _ " <tr class="odd">" & @CRLF & _ " <td align="center" class="change_arrow_fa"><span id="quoteElementPiece7" class="PriceTextUnchanged"><span class="fa fa-circle PriceTextUnchanged fa-fw"></span></span></td>" & @CRLF & _ " <td align="center" class="change"><span id="quoteElementPiece8" class="PriceTextUnchanged">0,00</span></td>" & @CRLF & _ " <td align="center" class="chgpct"><span id="quoteElementPiece9" class="PriceTextUnchanged">0,0%</span></td>" & @CRLF & _ " <td align="center" class="current_price"><span id="quoteElementPiece10" class="PriceTextUnchanged">0,01</span></td>" & @CRLF & _ " <td align="center"><span id="quoteElementPiece11" class="">0,01</span></td>" & @CRLF & _ " <td align="center"><span id="quoteElementPiece12" class="">0,01</span></td>" & @CRLF & _ " <td align="center"><span id="quoteElementPiece13" class="">0,01</span></td>" & @CRLF & _ " <td align="center"><span id="quoteElementPiece14" class="">0,01</span></td>" & @CRLF & _ " <td align="center"><span id="quoteElementPiece15" class="">10:00:00</span></td>" & @CRLF & _ " </tr>" & @CRLF & _ " </table>" & @CRLF & _ "</div>" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ " <div class="TableElement">" & @CRLF & _ " <table>" & @CRLF & _ " <tr>" & @CRLF & _ " <th class="boxToolTip" title="O número total de negócios que foram executados para PETRD197 durante o pregão mais recente.">Número de Negócios</th>" & @CRLF & _ " <th class="boxToolTip" title="Volume total negociado para PETRD197 Ex:19,7 hoje">Volume de Ações Negociadas</th>" & @CRLF & _ " " & @CRLF & _ " <th class="boxToolTip" title="">Preço Médio</th>" & @CRLF & _ " <th class="boxToolTip" title="O valor total financeiro para este ativo durante o pregão mais recente. Volume financeiro é um cálculo contínuo sobre todos os negócios do pregão. Para cada negócio no pregão você multiplica o preço pelo número de ativos negociados. Então some esse resultado para todos os negócios no pregão.">Volume Financeiro</th>" & @CRLF & _ " " & @CRLF & _ " <th class="boxToolTip" title="O volume médio diário durante os últimos 30 dias negociados.">Volume médio</th>" & @CRLF & _ " " & @CRLF & _ " <th class="boxToolTip" title="O valor mais baixo e mais alto que o ativo atingiu nas últimas 52 semanas">Últimas 52 Semanas</th>" & @CRLF & _ " " & @CRLF & _ " </tr>" & @CRLF & _ " <tr class="odd">" & @CRLF & _ " <td align="center"><span id="quoteElementPiece16" class="">7</span></td>" & @CRLF & _ " <td align="center"><span id="quoteElementPiece17" class="">22.000</span></td>" & @CRLF & _ " " & @CRLF & _ " <td align="center"><span id="quoteElementPiece18" class="PriceTextUnchanged">&nbsp;0,01</span></td>" & @CRLF & _ " <td align="center"></span><span id="quoteElementPiece19" class="">&nbsp;220</span></td>" & @CRLF & _ " " & @CRLF & _ " <td align="center">-</td>" & @CRLF & _ " " & @CRLF & _ " <td align="center">0,00 - 0,00</td>" & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ " </tr>" & @CRLF & _ " </table>" & @CRLF & _ " </div>" & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ " " & @CRLF & _ " <div class="TableElement">" & @CRLF & _ " <table>" & @CRLF & _ " <tr>" & @CRLF & _ " <th class="boxToolTip" title="O horário do último negócio realizado">Último Negócio</th>" & @CRLF & _ " <th>Tipo de Negócio</th>" & @CRLF & _ " <th>Quantidade de Ações Negociadas</th>" & @CRLF & _ " <th class="boxToolTip" title="O último preço negociado para PETRD197 Ex:19,7 (PETRD197).">Preço Negociado</th>" & @CRLF & _ " <th class="ColumnLast">Moeda</th>" & @CRLF & _ " </tr>" & @CRLF & _ " <tr class="odd">" & @CRLF & _ " <td align="center"><span id="quoteElementPiece20" class="">10:33:55</span></td>" & @CRLF & _ " <td align="center"><span id="quoteElementPiece21" class=""></span></td>" & @CRLF & _ " <td align="center"><span id="quoteElementPiece22" class="">100</span></td>" & @CRLF & _ " <td align="center" onclick="javascript:location.href='/bolsa-de-valores/bovespa/petrd197-ex-19-7-PETRD197/negocios'" style="cursor:pointer;text-decoration:underline;color:black;"><span id="quoteElementPiece23" class="trdprice current_price PriceTextUnchanged">&nbsp;0,01</span></td>" & @CRLF & _ " <td align="center"><span id="quoteElementPiece24" class="">BRL</span></td>" & @CRLF & _ " </tr>" & @CRLF & _ "" & @CRLF & _ " </table>" & @CRLF & _ " </div>" & @CRLF & _ " " & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "" & @CRLF & _ "<div class="TableElement">" & @CRLF & _ " <table>" & @CRLF & _ " <tr>" & @CRLF & _ " <th>Setor da Empresa</th>" & @CRLF & _ " </tr>" & @CRLF & _ " <tr class="odd">" & @CRLF & _ " <td align="center">" & @CRLF & _ " <a href="/mundo/brasil/setores/mineracao-extracao-petroleo-gas/extracao-petroleo-gas">Petróleo, Gás e Biocombustíveis / Petróleo, Gás e Biocombustíveis / Exploração e/ou Refino</a>" & @CRLF & _ " </td>" & @CRLF & _ " </tr>" & @CRLF & _ " </table>" & @CRLF & _ "</div>" & @CRLF & _ "" & @CRLF & _ "<div class="TableElement">" & @CRLF & _ " <table><tr><th>Anotações</th></tr><tr class='odd'><td><a href='#' role='login'>Clique aqui para escrever uma anotação sobre esse ativo.</a></td></tr></table>" 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