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

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

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php