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

/
/
gmu

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"(?i)PODATNIK\:[\s\a]*(?<NAZWA>[\S ]*)(?<KODPOCZTOWY>\d{2}-\d{3} )(?<LOKALIZACJA>[a-ż ]+)[\s\a]*ORYGINAŁ[\s\a]*\k<LOKALIZACJA>,[\s]*(?<DATA>\d{4}-\d{2}-\d{2})[\s\a]*(?<ULICA>[a-ż 0-9]*)[\s\a]*Bank[\s]*:[\s]*(?<BANK>[\w ]*)[\s\a]*NIP[\s]*:[\s]*(?<NIP>\d{3}-\d{3}-\d{3})[\s\a]*Konto[\s]*:[\s]*(?<KONTO>\d{26})[\s\a\S]*FAKTURA VAT[\s]*(?<NRFAKTURY>\d{2}\/\d{2}\/\d{4})*[\s\a]*Data wystawienia[\s\:]*(?<DATAWYSTAWIENIA>\d{4}-\d{2}-\d{2})[\s]*Data sprzedaży[\s\:]*(?<DATASPRZEDAZY>\d{4}-\d{2}-\d{2})[\s\a]*Na podstawie[\s\:]*(?<NAPODTSAWIE>[a-ż]\d{5}),[\s\a]*z dnia[\s]*:[\s]*(?<ZDNIA>\d{4}[-]?\d{2}[-]?\d{2})[\s\a]*NABYWCA[\s]*:[\s]*(?<NABYWCA>[\S ]*)[\s\a]*\(811\)[\s]*:[\s]*(?<ULICA2>[a-ż 0-9]*\d[a-z]{1,3} )(?<MIASTO>[a-ż]*)[\s\a]*,[\s\a]*(?<KODPOCZTOWY2>\d{2}[-]?\d{3})[\s\a]*N2P[\s]*:[\s]*(?<N2P>\d{3}[-]?\d{3}[-]?\d{2}[-]?\d{2})[\s\a]*Operator prowadzący[\s]*:[\s]*(?<OPERATOR>[a-ż ]*),[\s]*Tel.[\s]*:[\s]*(?<TEL>[0-9]{9}|[0-9 ]*)"; string input = @"PODATNIK: Rogum Kable Sp. z o.o. 83-000 Pruszcz Gdański ORYGINAŁ Pruszcz Gdański, 2020-04-28  Gruńwaldzka 66  Bank: Bank Polska Kasa Opieki SA  NIP : 000-111-111  Konto: 57124012681111001033385998  / FAKTURA VAT 07/04/2020 Data wystawienia : 2020-04-28 Data sprzedaży : 2020-04-28 Na podstawie : T59999, z dnia: 2019-12-28 NABYWCA : Pojazdy Szynowe PESA Bydgoszcz S.A. (811) : Zygmunta Augusta 11avb Bydgoszcz, 85-082 N2P : 554-031-17-75 Operator prowadzący : Łukasz Czajkowski, Tel.: 506234233, E-mail: l.czajkowski@rogum.com.pl / Poprzednie zaliczki/zadatki: Fzal 54/04/2020 2020-04-06 (246 000,00) Lp Nazwa pełna Ilość Jm Cena Wartość Stawka Wartość Wartość Indeks (K)      NETTO PL NETTO PLN VAT VAT PLN BRUTTO PLN   1 LiHCH 0,6/1kV 3x1,5 200 m 2,70 540,00 23% 124,20 664,20 9124-1100-000-075  2 LiHCH 0,6/1kV 3x1,5 86 m 2,70 232,20 23% 53,41 285,61 9124-1100-000-075  PRZED ODLICZ. ZAL./ZAD. - Zestawienie podatku VAT Netto Stawka VAT Brutto   772,20 23% 177,61 949,81        ODLICZENIE ZAL./ZAD. - Zestawienie podatku VAT Netto Stawka VAT Brutto   -772,20 23% -177,61 -949,81   Zestawienie podatku VAT Netto  Stawka VAT  Brutto          RAZEM (2 Poz.)  0,00   0,00 0,00  SUMA OGÓŁEM      0,00   Słownie : zero złotych, zero groszy DO ZAPŁATY : 0,00 zł Rozliczono Sara Żołnowska . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . podpis osoby upoważnionej pieczęć i podpis wystawiającego do odbioru Faktury VAT Druk Streamsoft PRESTIŻ lic. 5529 v. 7.0.347.168 Str. 1 z 1"; RegexOptions options = RegexOptions.Multiline | RegexOptions.CultureInvariant; foreach (Match m in Regex.Matches(input, pattern, options)) { Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index); } } }

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 C#, please visit: https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex(v=vs.110).aspx