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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "(?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 ]*)"; final String string = "PODATNIK:\n" + "Rogum Kable Sp. z o.o. 83-000 Pruszcz Gdański\n" + "ORYGINAŁ\n" + "Pruszcz Gdański, 2020-04-28\n" + "\n" + "Gruńwaldzka 66\n" + "\n" + "Bank: Bank Polska Kasa Opieki SA\n" + "\n" + "NIP : 000-111-111\n" + "\n" + "Konto: 57124012681111001033385998\n" + "\n" + "/\n" + "FAKTURA VAT 07/04/2020\n" + "Data wystawienia : 2020-04-28 Data sprzedaży : 2020-04-28\n" + " \n" + "Na podstawie : T59999, z dnia: 2019-12-28\n" + " \n" + "NABYWCA : Pojazdy Szynowe PESA Bydgoszcz S.A.\n" + "(811) : Zygmunta Augusta 11avb Bydgoszcz, 85-082 \n" + "N2P : 554-031-17-75\n" + "Operator prowadzący : Łukasz Czajkowski, Tel.: 506234233, E-mail: l.czajkowski@rogum.com.pl\n" + "/\n" + "Poprzednie zaliczki/zadatki: Fzal 54/04/2020 2020-04-06 (246 000,00)\n" + "Lp\n" + "Nazwa pełna\n" + "Ilość\n" + "Jm\n" + "Cena\n" + "Wartość\n" + "Stawka\n" + "Wartość\n" + "Wartość\n" + "Indeks (K)\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "NETTO PL\n" + "NETTO PLN\n" + "VAT\n" + "VAT PLN\n" + "BRUTTO PLN\n" + "\n" + "\n" + "1\n" + "LiHCH 0,6/1kV 3x1,5\n" + "200\n" + "m\n" + "2,70\n" + "540,00\n" + "23%\n" + "124,20\n" + "664,20\n" + "9124-1100-000-075\n" + "\n" + "2\n" + "LiHCH 0,6/1kV 3x1,5\n" + "86\n" + "m\n" + "2,70\n" + "232,20\n" + "23%\n" + "53,41\n" + "285,61\n" + "9124-1100-000-075\n" + "\n" + "PRZED ODLICZ. ZAL./ZAD. - Zestawienie podatku VAT\n" + "Netto\n" + "Stawka\n" + "VAT\n" + "Brutto\n" + "\n" + " \n" + "772,20\n" + "23%\n" + "177,61\n" + "949,81\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "ODLICZENIE ZAL./ZAD. - Zestawienie podatku VAT\n" + "Netto\n" + "Stawka\n" + "VAT\n" + "Brutto\n" + "\n" + " \n" + "-772,20\n" + "23%\n" + "-177,61\n" + "-949,81\n" + "\n" + " \n" + "Zestawienie podatku VAT\n" + "Netto\n" + "\n" + "Stawka\n" + "VAT\n" + "\n" + "Brutto\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "RAZEM (2 Poz.)\n" + "\n" + "0,00\n" + " \n" + "\n" + "0,00\n" + "0,00\n" + "\n" + "SUMA OGÓŁEM\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "0,00\n" + "\n" + "\n" + " \n" + "Słownie : zero złotych, zero groszy\n" + " \n" + "DO ZAPŁATY : 0,00 zł Rozliczono\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "Sara Żołnowska\n" + " \n" + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n" + "podpis osoby upoważnionej pieczęć i podpis wystawiającego do odbioru Faktury VAT\n" + "Druk Streamsoft PRESTIŻ lic. 5529 v. 7.0.347.168 Str. 1 z 1"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.UNICODE_CASE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html