Regular Expressions 101

Save & Share

  • Regex Version: ver. 31
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

/
/
gm

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 = "(?<=Country of origin Index.*\\n)(?:(?!ROBERTO)(?!Country of origin)[\\s\\S\\n])*"; final String string = "ROBERTO S.R.L. \n" + "Automotive Aftermarket\n" + "ROBERTO S.R.L., Str. Horia Macelariu nr. 30-34, RO-013937 Bucuresti\n" + "Capitalul Social: 169.363.000 Lei, Nr. Ord. Reg. com.: J40/7601/1994 \n" + " \n" + "Citibank Europe Plc Dublin, Romania Branch Citibank Europe Plc Dublin, Bulgaria Branch \n" + "SWIFT CODE: CITIROBU SWIFT CODE: CITIBGSF \n" + "IBAN RON: RO45 CITI 0000 0007 2488 3001 IBAN BGN: BG54 CITI 9250 1001 0086 00 \n" + "IBAN EURO: RO48 CITI 0000 0007 2488 3044\n" + "Invoice 1/ 2\n" + "Document No.: 2045158199\n" + "Date: 20.05.2022\n" + "Sold To party: 95100938\n" + "Account No.: 95100938\n" + "ALFREDO GIOACCHINO OOD \n" + "ul. Andrey Germanov 11 \n" + "BG-1336 SOFIA\n" + "Your VAT No.: BG175423111\n" + "Our VAT No.: RO5541546\n" + "Contact Person Finance: VALENTINA IVANOVA\n" + "Phone: +35929601062\n" + "E-mail: Valentina.Ivanova@bg.bosch.com\n" + "Contacts: IVA GYONEVA\n" + "Phone: +359029601056\n" + "E-mail: external.Iva.Gyoneva@bg.bosch.com\n" + "Sold To Address: ALFREDO GIOACCHINO OOD, ul. Andrey Germanov 11, BG-1336 SOFIA, B\n" + "Item Material/Description Quantity Unit Price per unit Net Value BGN\n" + "Transport: 1180736236 Shipping Point: ADC/LDC DE, Karlsruhe Shipping Type: Truck\n" + "Ship To Party: 95100938 ALFREDO GIOACCHINO OOD \n" + "ul. Andrey Germanov 11 \n" + "BG-1336 SOFIA\n" + "Delivery No.: 822656882 Delivery Date: 27.05.2022 Delivery Type: Standard Order AA\n" + "Your Order No.: 20220420-132109-436R From: 20.04.2022 Our Order No.: 15402739\n" + "10 Nozzle And Holder Assy 6 EA\n" + "Material: 0.432.191.301.741\n" + "Material Entered: 0.432.191.301\n" + "EAN: 3165143436226\n" + "82,32 493,92\n" + "Dispatch element: 105755352 6 EA\n" + "Your Order No.: 20220509-135611-091G From: 09.05.2022 Our Order No.: 210012705\n" + "20 Nozzle And Holder Assy 6 EA\n" + "Material: 0.432.191.301.741\n" + "Material Entered: 0.432.191.301\n" + "EAN: 3165143436226\n" + "82,32 493,92\n" + "Dispatch element: 105755352 6 EA\n" + "Your Order No.: 20220513-121235-468D From: 13.05.2022 Our Order No.: 210024679\n" + "30 mechanical steering pump 2 EA\n" + "Material: K.S00.000.394.002\n" + "Material Entered: K.S00.000.394\n" + "EAN: 4047025443456\n" + "565,00 1.130,00\n" + "Dispatch element: 105755352 2 EA\n" + "Total net value: 2.117,84\n" + "VAT:* Z9 0,00 % 2.117,84 0,00\n" + "Invoice amount: 2.117,84\n" + "* Triangular transaction taxable at the customer according to Art. 141, 2006/112/EC\n" + "Incoterms: DAP SOFIAROBERTO S.R.L. \n" + "Automotive Aftermarket\n" + "ROBERTO S.R.L., Str. Horia Macelariu nr. 30-34, RO-013937 Bucuresti\n" + "Capitalul Social: 169.363.000 Lei, Nr. Ord. Reg. com.: J40/7601/1994 \n" + " \n" + "Citibank Europe Plc Dublin, Romania Branch Citibank Europe Plc Dublin, Bulgaria Branch \n" + "SWIFT CODE: CITIROBU SWIFT CODE: CITIBGSF \n" + "IBAN RON: RO45 CITI 0000 0007 2488 3001 IBAN BGN: BG54 CITI 9250 1001 0086 00 \n" + "IBAN EURO: RO48 CITI 0000 0007 2488 3044\n" + "Invoice 2/ 2\n" + "Document No.: 2045158199\n" + "Date: 20.05.2022\n" + "Sold To party: 95100938\n" + "Account No.: 95100938\n" + "Payment terms: Up to 03.06.2022 you receive 2,000 % discount\n" + "Up to 19.06.2022 without deduction\n" + "Country of origin Index (represents the last three digits of part number)\n" + "Brazil 741\n" + "Germany 002\n" + "Country of origin HS Code Quantity UoM Amount BGN\n" + "Brazil\n" + "84099900 12 EA 987,84\n" + "987,84\n" + "Germany\n" + "84136061 2 EA 1.130,00\n" + "1.130,00\n" + "Marking Dispatch element type Physical dimension of dispatch \n" + "element\n" + "Unit of \n" + "measure\n" + "Gross \n" + "Weight Unit of measure\n" + "105755352 Corrug. brown box RB-logo 550X35 550 350 300 MM 14,880 KG\n" + "Country of origin Item numbers Total amount\n" + "Brazil 10 20 987,84\n" + "Germany 30 1.130,00\n" + "Element type: Corrug. brown box RB-logo 550X35Number of elements: 1 14,880 KG"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); 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