Regular Expressions 101

Save & Share

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
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
Processing...

Test String

Code Generator

Generated Code

import re regex = re.compile(r"(?i)(?m)(?<![a-z]|\.|\.\d)(?:\d{1,4})(?:[.,\s]\d{3})*(?:[.,]\d{2})(?!\%|\d|\.|\s\.|\scm|cm|pol|\spol)") test_str = ("TICKET RESTAURANT DE PORTUGAL,\n" "Infante Santo,\n" "1350—177 Lisboa\n\n" "S.A.\n\n" "AV. 23 A/D\n\n" "NIF e MAT.:\n" "Cap.\n\n" "500423849\n\n" "Soc. 500.000 Euros\n\n" "Z43\n\n" "CDUCket\n\n" ";fensmoº\n\n" "000370.19\n\n" "FAS—SISTEMAS DE INFORMACAO LDA\n\n" "TAGUS PARK\n\n" "EDIFICIO QUALIDADE B2-1B\n\n" "2740—120 PORTO SALVO\n\n" " \n\n" " \n\n" " \n\n" " \n\n" " \n\n" " \n\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "r\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "W\n" "[\n\n" " \n\n" " \n\n" " \n\n" " \n\n" " \n\n" " \n\n" "fwj+—Processado por programa certificado n.\n\n" ". ticket\n\n" "SEFVIÇOS Delegação Nºrte\n\n" "R. das Cardosas, 1495\n" "4425 - 510 S.Pedro Fins Maia\n\n" "Delegação Sul\n\n" "Av. Infante Santo, 21 A\n\n" "1350-177 Lisboa\n\n" "Tel. 210 420 325 - Fax. 210 420 365\n\n" "Hcket©tkketpt\n" "Hcketpt\n\n" "Pagamento por transferencia bancaria:\n" "IBAN: PT50 0079 0000 64938339101 80\n\n" "Delegação Centro\n\n" "R. Álvaro Pires de Miranda,\n" "Lt. 46 ,1.º Dto. A ' 2415-369 Leiria\n" "Tel. 228 302 900 ' Fax. 228 302 904 Tel. 244 826 378 ' Fax. 244 823 689\n\n" "2292/AT\n\n" "W V/REQUISIÇÃO V/Nº CONTRIBUINTE Nº CLIE_NTE W DATA W\n" "WI \"\"\" 777 “ª\" ' W ORIGINAL DA ;\n" "W WPT 502524588 EET 000370W 2017— 05- 03 FACTURA FET 17/1208\n" "TICKET ENSINO fornecidos: , , W\n" "% QUANHDADE ; VALORUNnAmo W VALORTOTAL\n" "Emissão Ticket Ult. Ticket Cod. Produto « W\n" "17002775 00015396 00015397 105.00/ET W 2W 105.00W 210.00\n" "17002776 00015398 00015400 140.00/ET W 3; 140.00W 420.00\n" "W W\n" "W ? W\n" "W * W\n" "., W\n" "W W W\n" "W W\n" "1 W W\n" "W . í\n" "W IVA ISENTO — Alineas &) e c) . 27 Artigo 9 W 5 W SUB-TOTAL * 630 . OOW (*)\n" "L “2__ W W _“ “__mw ___-“ _, \"I\n" "W wannn CWAEWKO 6.50% 23% TOTAL€\n" "& Euros 630.00 40.95 .42 680.37\n" "& Euros 630.00 40.95 9.42 680.37\n" "288.890.234,23\n" "SEISCENTOS E OITENTA EUROS E TRINTA E SETE CENTIMOS ****************\n" "********************************************************************\n\n" "SWIFT/BIC: BPNPPTPL\n\n" "at\n\n" "Delegação Madeira\n\n" "Calçada de São Lourenço, nº 3, 2 C\n" "9000-061 Funchal\n\n" "Tel. 291 225 727 ' Fax. 291 230 694\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