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

/
/
msu

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 = "(?msu)(?=(?:""\s+?Controle\s*Fiscal[\w\W]+?)?""\s+(?<NomeUc>[\w\W]+?)$(?:.*?)""\s+?(?<Cnpj>\d{14})\s*(?:.*?)(?<MesReferencia>\d{2}\/\d{4})(?:.*?)(?<DtEmissao>\d{2}\/\d{2}\/\d{4})(?:.*?)\d{2}\/\d{2}\/\d{4}\s+(?<NumFatura>\d+)\s+(?:.*?)(?<ExternalCode>\d+-\d+)\s+(?:.*?)(?<DtVencimento>\d{2}\/\d{2}\/\d{4})\s+(?:.*?)(?<VlrTotalFatura>[0-9\.]+,?\d*)(?:.*?)Consta\snesta\sfatura\s*R.\s(?<VlrPisCofins>[0-9\.]+,?\d*)\sreferentes\sa\s(?:.*?)(?<AliqPis>[0-9\.]+,?\d*)%\sde\sPIS\se\s(?:.*?)(?<AliqCofins>[0-9\.]+,?\d*)%\sde\sCOFINS(?:.*?)\)\s+\d+\s+(?:\d+)?\s+(?<VlrBaseIcms>[0-9\.]+,?\d*)(?:.*?)""\s+(?<AliqIcms>\d+)\s+(?:.*?)^(?<DContratadaFp>[0-9\.]+,?\d*)\s+(?:.*?)[0-9\.]+,?\d*\s+(?<VlrIcms>[0-9\.]+,?\d*)\s+(?:.*?)""\s+(?<DataLeituraAtual>\d{2}\/\d{2}\/\d{4})\s+(?:.*?)(?<DataLeituraAnterior>\d{2}\/\d{2}\/\d{4})\s+(?:.*?)""\s+(?<LeituraAtualCFp>[0-9\.]+,?\d*)\s+(?:.*?)(?<LeituraAnteriorCFp>[0-9\.]+,?\d*)\s+(?:.*?)(?<ConstanteConsumoFp>[0-9\.]+,?\d*)\s+(?:.*?)(?<CMedidoFp>[0-9\.]+,?\d*)\s+(?:.*?)(?<LeituraAtualCP>[0-9\.]+,?\d*)\s+(?:.*?)(?<LeituraAnteriorCP>[0-9\.]+,?\d*)\s+(?:.*?)(?<ConstanteConsumoP>[0-9\.]+,?\d*)\s+(?:.*?)(?<CMedidoP>[0-9\.]+,?\d*)(?:.*?))" Local $sString = """ Controle Fiscal: 0B3EADFCEE1EECF867DEBB24AB24C691" & @CRLF & _ """ AGUAS DE NITEROI S/A " & @CRLF & _ """ ROD BR 101 KM 30,5, S/N DISTRITO CONSELHEIRO " & @CRLF & _ """ 02150336000166 0704097" & @CRLF & _ """ 86 41570091 0108-8" & @CRLF & _ """ FAZ NOVA GAIVOT 12/2019" & @CRLF & _ """ CAMPOS DOS GOYTACAZES 20/12/2019" & @CRLF & _ """ 28100-000 24/12/2019" & @CRLF & _ "4421 Segunda Via" & @CRLF & _ "7889020-9 16/01/2020 2.447,37" & @CRLF & _ "Cons Fat Ponta 814,00 kWh2,781802.264,38" & @CRLF & _ "Cons Fat F Ponta 8568,00 kWh 0,541594.640,34" & @CRLF & _ "Dem Fat F Ponta 73,00 kW31,790002.320,67" & @CRLF & _ "Ajuste -4.833,30" & @CRLF & _ "Iluminacao Publica 126,69" & @CRLF & _ "ENERGIA CONSUMIDA GD BAND VERDE 6.015,70" & @CRLF & _ "Cred Energia Injetada G. Distribuida -6.015,70 0,00" & @CRLF & _ "Devolucao ICMS -2.071,41" & @CRLF & _ """ 0,00" & @CRLF & _ "VR ADIC BAND AMARELA DO MES ( R$ 347,52 ) " & @CRLF & _ "Consta nesta fatura R$ 533,22 referentes a 1,04% de PIS e 4,74% de COFINS " & @CRLF & _ "(Art. 10 Res. 298/2006-ANEEL e Leis N. 10.637/02 e 10.883/03) " & @CRLF & _ "33375978 9.225,39 " & @CRLF & _ """ 30 " & @CRLF & _ "1.000,00 0,00 2.767,61 " & @CRLF & _ "Tipo de Faturamento: Normal " & @CRLF & _ "19/12/2019 19/11/2019 19/12/2019 19/11/2019" & @CRLF & _ "357,00 255,00 84,000 8568,00 3555,00 2586,00 0,840 814,00" & @CRLF & _ "63,00 41,00 3,360 73,00 46,00 30,00 3,360 53,00" & @CRLF & _ "1,00 1,00 84,000 0,00 0,00 0,00 0,840 0,00" & @CRLF & _ "219,00 140,00 0,840 66,36 137,00 89,00 0,840 40,32" & @CRLF & _ """ 13,80 kV IGOR MACHADO" & @CRLF & _ """ 20/01/2020" & @CRLF & _ "0 0 0 0 0 THS VERDE A4 C/DES15Telefone:2716-1634" & @CRLF & _ "0 0 0 0 14,49 kV" & @CRLF & _ "0 0 E-mail:igor.santos@enel.com10/2019 Servico Publico" & @CRLF & _ """ 12,83 kV 0,00%" & @CRLF & _ "0 0 " & @CRLF & _ "Banco Itaú SA 341-7 34191.09008 30346.832931 83707.520009 1 81360000244737 " & @CRLF & _ "PAGÁVEL PREFERENCIALMENTE NO ITAÚ Contra-apresentação" & @CRLF & _ "AMPLA Energia e Serviços S.A. 2938/37075-2" & @CRLF & _ "20/12/2019 4421 DP N 175/00303468-3" & @CRLF & _ """ 175 2.447,37" & @CRLF & _ "Pagamentos efetuados após o dia 16/01/2020, incorrerão encargos financeiros de mora. " & @CRLF & _ "Os encargos financeiros citados, serão cobrados em faturas posteriores. " & @CRLF & _ "Regime Especial - processo no E-04/142.091/97 " & @CRLF & _ "AGUAS DE NITEROI S/A " & @CRLF & _ "ROD BR 101 KM 30,5, S/N DISTRITO CONSELHEIRO " & @CRLF & _ """ CONTA PAGA " & @CRLF & _ "" Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYFULLMATCH) ; 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