Regular Expressions 101

Save & Share

  • Save new Regex
    ctrl+s
  • Update 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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

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