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 = "(?:Nr.\s*nota\s*Folha\s*Data\s*preg.o\n(?<numNota>\d+)\s*(?<numFolha>\d+)\s*(?<dataPregao>\d{2}\/\d{2}\/\d{4})\s*(?<corretora>.+)\n(?:1-BOVESPA\s*.*\n)+Resumo\s*dos\s*Neg.cios\s*)" Local $sString = "Nr. nota Folha Data pregão" & @CRLF & _ "2807356 1 02/03/2020" & @CRLF & _ "CLEAR CORRETORA - GRUPO XP" & @CRLF & _ "1-BOVESPA C VISTA GERDAU METPN ED N1 100 8,00 800,00 D" & @CRLF & _ "1-BOVESPA C VISTA ITAUSAPN EDJ N1 200 12,10 2.420,00 D" & @CRLF & _ "1-BOVESPA C VISTA ITAUSAPN EDJ N1 D 500 12,00 6.000,00 D" & @CRLF & _ "1-BOVESPA V VISTA ITAUSAPN EDJ N1 D 100 12,11 1.211,00 C" & @CRLF & _ "1-BOVESPA V VISTA ITAUSAPN EDJ N1 D 100 12,11 1.211,00 C" & @CRLF & _ "Resumo dos Negócios " & @CRLF & _ "Debêntures 0,00" & @CRLF & _ "Vendas à vista 2.422,00" & @CRLF & _ "Compras à vista 9.220,00" & @CRLF & _ "Opções - compras 0,00" & @CRLF & _ "Opções - vendas 0,00" & @CRLF & _ "Operações à termo 0,00" & @CRLF & _ "Valor das oper. c/ títulos públ. (v. nom.) 0,00" & @CRLF & _ "Valor das operações 11.642,00" & @CRLF & _ "Resumo Financeiro " & @CRLF & _ "Clearing " & @CRLF & _ "Valor líquido das operações 6.798,00 D" & @CRLF & _ "Taxa de liquidação 2,83 D" & @CRLF & _ "Taxa de Registro 0,00 D" & @CRLF & _ "Total CBLC 6.800,83 D" & @CRLF & _ "Bolsa " & @CRLF & _ "Taxa de termo/opções 0,00 D" & @CRLF & _ "Taxa A.N.A. 0,00 D" & @CRLF & _ "Emolumentos 0,39 D" & @CRLF & _ "Total Bovespa / Soma 0,39 D" & @CRLF & _ "Custos Operacionais " & @CRLF & _ """ " & @CRLF & _ "Taxa Operacional 0,00 D" & @CRLF & _ "Execução 0,00 " & @CRLF & _ "Taxa de Custódia 0,00 " & @CRLF & _ "Impostos 0,00 " & @CRLF & _ "I.R.R.F. s/ operações, base R$0,00 0,00 " & @CRLF & _ "Outros 0,00 C" & @CRLF & _ "Total Custos / Despesas 0,00 D" & @CRLF & _ "Nr. nota Folha Data pregão" & @CRLF & _ "3408171 1 11/03/2020" & @CRLF & _ "CLEAR CORRETORA - GRUPO XP" & @CRLF & _ "1-BOVESPA C VISTA VIVER ON NM 100 1,79 179,00 D" & @CRLF & _ "Resumo dos Negócios " & @CRLF & _ "Debêntures 0,00" & @CRLF & _ "Vendas à vista 0,00" & @CRLF & _ "Compras à vista 179,00" & @CRLF & _ "Opções - compras 0,00" & @CRLF & _ "Opções - vendas 0,00" & @CRLF & _ "Operações à termo 0,00" & @CRLF & _ "Valor das oper. c/ títulos públ. (v. nom.) 0,00" & @CRLF & _ "Valor das operações 179,00" & @CRLF & _ "Resumo Financeiro " & @CRLF & _ "Clearing " & @CRLF & _ "Valor líquido das operações 179,00 D" & @CRLF & _ "Taxa de liquidação 0,04 D" & @CRLF & _ "Taxa de Registro 0,00 D" & @CRLF & _ "Total CBLC 179,04 D" & @CRLF & _ "Bolsa " & @CRLF & _ "Taxa de termo/opções 0,00 D" & @CRLF & _ "Taxa A.N.A. 0,00 D" & @CRLF & _ "Emolumentos 0,00 D" & @CRLF & _ "Total Bovespa / Soma 0,00 C" & @CRLF & _ "Custos Operacionais " & @CRLF & _ """ " & @CRLF & _ "Taxa Operacional 0,00 D" & @CRLF & _ "Execução 0,00 " & @CRLF & _ "Taxa de Custódia 0,00 " & @CRLF & _ "Impostos 0,00 " & @CRLF & _ "I.R.R.F. s/ operações, base R$0,00 0,00 " & @CRLF & _ "Outros 0,00 C" & @CRLF & _ "Total Custos / Despesas 0,00 D" & @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