Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

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

$re = '/(\d{1,2})(\s)(\xA0\xA0)(\s)(\d{1,7})(\s)(\w.+)(\s)(\d{1,3}\.\d{1,3}|\d{1,3})(\s)(\w\w)(\sx\s)(\d{1,3}\,\d{1,2})(\s)(\(\d\)|\(\d{1,3}\.\d{1,2}\))(( (0)(\s)(\d{1,3}\,\d\d)|(\s)(\n)(\xA0\xA0\xA0\xA0\sDesconto\s)([0-9]{1,3}\,[0-9]{2})(\n)(-\s[0-9]{1,2}\,[0-9]{2})))/m'; $str = 'REAL PARQUE CNPJ 47.508.411/0617-08 IE 116804053119 CIA BRASILEIRA DE DISTRIBUICAO AV MAGALHAES DE CASTRO 6118 SAO PAULO - SP CUPOM FISCAL ELETRÔNICO - SAT CPF/CNPJ do Consumidor: 007.270.248-68 Razão Social/Nome: AGUINALDO BERLOFFE #   |   COD   |   DESC   |   QTD   |   UN   |   VL UN R$   |   (VLTR R$)*   | VL ITEM R$ 1    7047411 LEITE NIN NESTLE 1LT 3 UN x 4,69 (14.07)      Desconto 14,07 - 2,70 , 2    0790642 CERV HEINEKEN 350ML 12 UN x 3,49 (41.88) 0 41,88 , 3    4231486 LT SEMI DES NINHO 1L 1 UN x 4,69 (4.69)      Desconto 4,69 - 0,90 , 4    1103188 VODKA VORUS 1L 1 UN x 25,99 (25.99) 0 25,99 , 5    1049831 ARROZ INTEGRAL PF 1K 2 UN x 4,09 (8.18) 0 8,18 , 6    6009229 QA ARROZ T1 1KG 1 UN x 2,99 (2.99) 0 2,99 , 7    3878682 TQ AGUA COCO TAEQ 1L 2 UN x 7,49 (14.98) 0 14,98 , 8    8788801 IOG.FAZ.BELA VISTA M 1 UN x 3,79 (3.79) 0 3,79 , 9    4299066 IOG B VISTA F V 500G 2 UN x 3,79 (7.58) 0 7,58 , 10    6803186 COGUMEL QUALITA 100G 2 UN x 5,99 (11.98) 0 11,98 , 11    5616947 KETCHUP HEINZ 397GR 1 UN x 8,99 (8.99) 0 8,99 , 12    1207692 BIFE COPA LOMBO 1KG 1 UN x 19,94 (19.94) 0 19,94 , 13    0076937 BACON DEF KG 0.298 KG x 35,49 (10.58) 0 10,58 , 14    0001311 PEITO FGO C/OSSO KG 0.972 KG x 9,99 (9.71) 0 9,71 , 15    0226998 PATINHO BIFES ATP 0.528 KG x 34,99 (18.47) 0 18,47 , 16    0226998 PATINHO BIFES ATP 0.54 KG x 34,99 (18.89) 0 18,89 , 17    0001311 PEITO FGO C/OSSO KG 0.914 KG x 9,99 (9.13) 0 9,13 , 18    1161632 BISNAGUIN PAN 300G 1 UN x 6,69 (6.69) 0 6,69 , 19    1197527 MAC SPAG LA MOLISANA 1 UN x 2,29 (2.29) 0 2,29 , 20    0787055 MAC REN SUP PEN 500G 1 UN x 6,59 (6.59) 0 6,59 , 21    2022369 GR DR FUSIL ADRIA 50 1 UN x 5,59 (5.59) 0 5,59 , 22    3197899 QA OVO VM GD LG C/10 2 UN x 11,90 (23.8) 0 23,80 , 23    1090871 QA CENOURA 500G 1 UN x 4,79 (4.79) 0 4,79 , 24    3209950 QA MILHO VERDE 700G 1 UN x 6,49 (6.49) 0 6,49 , 25    1091830 PIMENTAO VERM 300G 1 UN x 4,99 (4.99) 0 4,99 , 26    0287760 CEBOLA GRANEL KG 1.165 KG x 7,98 (9.3) 0 9,30 , 27    0287753 BATATA GRANEL KG 1.47 KG x 7,98 (11.73) 0 11,73 , 28    1207899 QA NOZES SC NAC 140G 1 UN x 25,39 (25.39) 0 25,39 , 29    1090796 QA BERINJELA COMUM 1 UN x 4,39 (4.39) 0 4,39 , 30    0251280 KIWI IMP GNEL KG 0.525 KG x 21,99 (11.54) 0 11,54 , 31    5107452 CHUCHU VDE ESC 600G 1 UN x 2,69 (2.69) 0 2,69 , 32    0357593 TOMATE ITALIANO KG 1.04 KG x 7,69 (8) 0 8,00 , 33    4600039 QA CER ULT FLAK 300G 1 UN x 5,99 (5.99)      Desconto 5,99 - 1,50 , 34    0337182 GENGIBRE GNEL KG 0.805 KG x 12,39 (9.97) 0 9,97 , 35    0227841 MANGA PALMER NAC KG 0.655 KG x 5,49 (3.6) 0 3,60 , 36    0247528 MACA FUJI KG 0.64 KG x 9,98 (6.39) 0 6,39 , 37    6072100 QA UVA VERM SS 500G 1 UN x 8,29 (8.29) 0 8,29 , 38    4333364 ALFACE AMERICANA 250 2 UN x 3,49 (6.98) 0 6,98 , 39    0219631 MAMAO FORMOSA KG 1.64 KG x 5,49 (9) 0 9,00 , 40    1177380 QA SALGAD BACON 100G 1 UN x 3,59 (3.59) 0 3,59 , 41    7533006 PAO 100 INT G CAST 1 UN x 8,99 (8.99) 0 8,99 , 42    1225200 QA BISC AVEI MEL170G 2 UN x 2,29 (4.58) 0 4,58 , 43    1121371 BISC CERE MAC/UV141G 2 UN x 3,39 (6.78) 0 6,78 , 44    1045921 QA SALG CEBOLA 100G 1 UN x 4,99 (4.99) 0 4,99 , 45    0049771 MORT BOL TR CER FTKG 0.128 KG x 39,90 (5.11) 0 5,11 , 46    0012775 PRES COZ SAD MAGRO 0.158 KG x 19,90 (3.14) 0 3,14 , 47    0013116 SALAME IT SAD SSS KG 0.104 KG x 69,99 (7.28) 0 7,28 , 48    0143745 QA QJ MUSS QA FAT 0.262 KG x 33,69 (8.83)      Desconto 8,83 - 1,78 , 49    7094651 AMEND JAP YOKI 500G 1 UN x 9,59 (9.59) 0 9,59 , 50    5758203 PAO HOT DOG 200G 1 UN x 8,19 (8.19) 0 8,19 TOTAL R$ 480,52 Troco R$ 0,00 OBSERVAÇÕES DO CONTRIBUINTE Datalov: 20200510 Loja: 1299 Terminal: 110 NCupon: 00281819 Valor aproximado dos tributos deste cupom R$ 101,77 (conforme Lei Fed. 12.741/2012) SAT No. 110 10/05/2020 10:57:23 35200547508411061708651100000347431306165855'; 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