Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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

/
/
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 = "(?<=P ).*"; final String string = "List Bill Number: 91612223 Remit To:\n" + "List Bill Date: September 28, 2020 P.O. Box 9121\n" + " Minneapolis, MN 55480-9121\n" + " Bill-to:\n" + " C8144459\n" + " ATTN: ACCOUNTS PAYABLE XYZ Worldwide, Inc. and\n" + " ABCUC Subsidiaries\n" + " DONORE\n" + " DROG\n" + " qwefghj List Bill Invoice Total: USD 2,127.84\n" + " List Bill Invoice Balance: USD 2,127.84\n" + " Payment Due: October 10, 2020\n" + " List Bill\n" + "Group: C8144459\n" + "Load # Invoice Number Invoice Total Invoice Balance\n" + "333311392 6124765056 USD 447.74 USD 447.74\n" + " Type Location Name City/State/Zip BOL Actv Date # PCS Stop Ref. Number\n" + " P Barrett Distribution Centers Somerset, NJ 08873 5027905 09/08/2020 290 CAS 5027905\n" + " D 102- Wegmans GMDC ROCHESTER, NY 14623 09/15/2020\n" + "Load # Invoice Number Invoice Total Invoice Balance\n" + "333698986 6124960145 USD 358.78 USD 358.78\n" + " Type Location Name City/State/Zip BOL Actv Date # PCS Stop Ref. Number\n" + " P Barrett Distribution Centers - Memphis, TN 38141 5028124 09/09/2020 48 PLT 5028124\n" + " Memphis\n" + " D Walgreens Moreno Valley, Moreno Valley, CA 92551 09/17/2020\n" + "Load # Invoice Number Invoice Total Invoice Balance\n" + "333803610 6125029363 USD 347.78 USD 347.78\n" + " Type Location Name City/State/Zip BOL Actv Date # PCS Stop Ref. Number\n" + " P Barrett Distribution Centers - Memphis, TN 38141 5028208 09/10/2020 12 CAS 5028208\n" + " Memphis\n" + " D NATIONAL ECZEMA Novato, CA 94945 09/18/2020\n" + " ASSOCIATION\n" + "Load # Invoice Number Invoice Total Invoice Balance\n" + "334236950 6125032211 USD 567.88 USD 567.88\n" + " Type Location Name City/State/Zip BOL Actv Date # PCS Stop Ref. Number\n" + " P Barrett Distribution Centers Somerset, NJ 08873 5028225 09/16/2020 230 CAS 5028225\n" + " D C AND S WHOLESALE Bethlehem, PA 18020 09/18/2020\n\n" + " Page 1 of 3List Bill Number: 91612223 Remit To:\n" + "List Bill Date: September 28, 2020 P.O. Box 9121\n" + " Minneapolis, MN 55480-9121\n" + " Bill-to:\n" + " C8144459\n" + " ATTN: ACCOUNTS PAYABLE XYZ Worldwide, Inc. and\n" + " ABCUC Subsidiaries\n" + " DONORE ROAD INDUSTRIAL ESTATE\n" + " DR\n" + " IRELAND List Bill Invoice Total: USD 2,127.84\n" + " List Bill Invoice Balance: USD 2,127.84\n" + " Payment Due: October 10, 2020\n" + " List Bill\n" + "Group: C8144459\n" + "Load # Invoice Number Invoice Total Invoice Balance\n" + "334365135 6125220068 USD 187.78 USD 187.78\n" + " Type Location Name City/State/Zip BOL Actv Date # PCS Stop Ref. Number\n" + " P Barrett Distribution Centers - Memphis, TN 38141 5028451 09/16/2020 16 CAS 5028451\n" + " Memphis\n" + " D WALGREENS 075044 WILLIAMSTON, SC 29697 09/23/2020\n" + "Load # Invoice Number Invoice Total Invoice Balance\n" + "333285686 6125333531 USD 217.88 USD 217.88\n" + " Type Location Name City/State/Zip BOL Actv Date # PCS Stop Ref. Number\n" + " P Barrett Distribution Centers - Memphis, TN 38141 5027871 09/03/2020 29 CAS 5027871\n" + " Memphis\n" + " D WALGREENS-WINDSOR Windsor, WI 53598 09/11/2020\n" + "Group Total: # of Invoices Invoice Total Invoice Balance\n" + "C8144459 6 USD 2,127.84 USD 2,127.84\n\n" + " Page 2 of 3List Bill Number: 91612223 Remit To:\n" + "List Bill Date: September 28, 2020 P.O. Box 9121\n" + " Minneapolis, MN 55480-9121\n" + " Bill-to:\n" + " C8144459\n" + " ATTN: ACCOUNTS PAYABLE XYZ Worldwide, Inc. and\n" + " ABCUC Subsidiaries\n" + " DONORE ROAD INDUSTRIAL ESTATE\n" + " ab\n" + " asdfghj List Bill Invoice Total: USD 2,127.84\n" + " List Bill Invoice Balance: USD 2,127.84\n" + " Payment Due: October 10, 2020\n" + " List Bill\n" + "Grand Totals for Customer # of Invoices Charges Accessorials Adjustments Invoice Total Payments Invoice Balance\n" + " 6 USD 1,634.89 USD 492.95 USD 0.00 USD 2,127.84 USD 0.00 USD 2,127.84\n\n" + " XYZ wants to ensure your payment is applied to your account as intended.\n" + " Please reference the List Bill number on your payment. If there is a payment amount difference on this List Bill, please\n" + " provide detail including the individual invoice numbers provide and the reason of the payment discrepancy.\n" + " Thank You.\n\n" + " XYZ Company, Inc., 14800 Ch, Suite 1500, Eden Prairie, MN 55347\n" + " Fed Tax ID 12-1234567, DNB 1234567, MC 12344\n\n" + " Page 3 of 3"; 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