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

r"
"
gm

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"^[-+.]?\d(.*[\da-zA-Z])?$"; string input = @"Date : 12/21/2021 BILL OF LADING Page 1 SHIP FROM Bill of Lading Number : 0233052667 Name : KUBOTA TRACTOR CORPORATION Address : 31700 W 207TH ST City/State/Zip : EDGERTON KS 66021 SID# FOB : SHIP TO Carrier Name : XPO Freight Name : FLORIDA COAST EQUIPMENT, LLC Location# : Trailer Number : Address : 2114 SOUTH ORANGE BLOSSOM Seal Number(s) : SCAC : CNWY City/StatelZip : APOPKA FL,32703 CID# FOB : Pro number : 540409004 THIRD PARTY FREIGHT CHARGES BILL TO Name : Kubota Tractor Address : c/o Simplified Logistics, LLC PO BOX 40088 Freight Charge Terms : (freight charges are prepaid City/State/Zip : Bay Village, OH, 44140 unless marked otherwise). Ref# : 0233052667 Prepaid X Collect 3rd Party Master Bill Of Lading with attached (check box) underlying Bills of Lading SPECIAL INSTRUCTIONS : CUSTOMER ORDER INFORMATION CUSTOMER ORDER NUMBER #PKGS WEIGHT PALLET/SLIP ADDITIONAL SHIPPER INFO (CIRCLE ONE) 12105 1 164.000 Y N : ANTAI Hours piek-up TEC : 1 2017 GRAND TOTAL 1 164.000 CARRIER INFORMATION HANDLING UNIT. PACKAGE COMMODITY DESCRIPTION LTLONLY brattention Commodities in requiring handling special or stowing or adottional must be marked care and QTY TYPE QTY TYPE WEIGHT H.M See Backaged Section as to 2(0) ensure Of NMFC safe Item transportation 360 with ordinary care.. NMFC# CLASS X) .1 PLT 164.000 Tractor Parts : 50 : 164.000 ЕВ : GRAND TOTAL Where the rate is dependent on value shippers are required to state specifically in writing the agreed or COD Amount : declared ""The agreed value or of declared the property value of as follows the property : is specifically stated by the shipper to be not exceeding Fee Terms Collect : $ Prepaid : per Customer Check Acceptable : Note : Liabilty Limitation for loss or damage in this shipment may be applicable. See 49 U.S.C.-14706(0)1/A)and(B). RECEIVED, subject to individually determined rates or contracts that have been agreed upon in writing The carrier shall not make delivery of this shipment without between the carrier and shipper if applicable otherwise to the rates, classification and rules that have been payment of freight and all other lawful charges she/he established is familiar by the with carrier all the and terms are available and conditions to the shipper, of the NMFC on request. Uniform The Straight shipper Bill hereby Of Lading, certifies including that _Shipper those on the back thereof, and the said terms and.conditions are hereby agreed to by the shipper and Signature accepted for him/herself and his/her assigns This is to certify that the above named material Trailer Loaded Freight Counted CARRIER SIGNATURE/PICKUP DATE are properly classified, packaged, marked and Carrier acknowledge receipt of packages and required transportation labeled and are according in proper to condition the applicable for By Shipper By Shipper placards. Carrier certifies emergency response regulations of the DOT. By Driver By Driver/pallets information DOT emergency was made response available guidebook and/or and carrier or equivalent has the said to contain documentation in the vehicle : Property described above is SHIPPER SIGNATURE/DATE received in good order, except as noted. 中 By Driver/pieces 52 Date : 12/16/21 BILL OF LADING Page : 1 of 1 Valve Bill of Lading Number : 0002935540 Naine : Hydraulic Phone : Address 1 : 373 Meuse Argonne Address 2 : USSID# City/St/ZIP/Country : HICKSVILLE, OH, 43526, : 711379002 FOB : CARRIER NAME : XPO Logistics Trailer Number; Name : 094-ROANOKE MANUFACTURING Seal Number : (s) : Phone : Address 1 : 325 S CENTER DR SCAC : XPOL Address2 : DOOR 94 Pro Number : 521337482 City/St/Zip/Country : DALEVILLEVA, 24083, US CID # : 880068-12675 FOB; Name : ALTEC C/O CHRLTL Address1 : 14800. CHARLSON ROAD EDEN Freight Charge Terms : (freight charges are prepaid Address2 : City/St/Zip/Country : EDEN PRAIRIE, MN, 55347, US unless markedotherwise) SPECIAL INSTRUCTIONS : Prepaid : Collect Third Party X Master Bill of Lading : with attached underlying Bills of Lading CUSTOMER ORDER NUMBER #PKGS VOLUME WEIGHT PALLET/SLIP ADDITIONAL. SHIPMENT INFO (circle one) 880068-12675 1 0.0 162 : 00 Y (N) GRAND TOTAL 0.0 CF 162.00 LB HANDLING PACKAGE H.M. COMMODITY DESCRIPTION LTL ONLY UNIT {X) Commodities roquiring special or additional care or attention in : llandling or stowing must be so marked and packaged QTY TYPEQTY TYPE VOLUME WEIGHT so as to ensure safer transportation with ordinary care NMFC# CLASS Sce Scction 21e) or NMFC Item 3:00 1 #3 1/2 PALLET 0.0 162.00 PARTS, EXCEPT VALVE BODIES, OF VALVES Driver's signature acknowledges receipt of freight only. Received shipment is subject to terms of a written contract, if any, otherwise subject to 521-337482 the terms, conditions and limitations of liability set forth in XPO Logistics Freight, Inc. rules tariff (see www.xpo.com) XPOLogistics HOS 162.00 L GRAND : TOTAL Wiere llie rate is depended on value, Slippers are required lo stari specifically in writing the COD Amount agreed or declared value of the properly as follows : The agreed declared value of the property is specifically stated by the shipper to be not excecding Fee Terms Collect Prepaid per Customer check acceptable NOTE Libillty Limitation for loss or damage in this shipment may be applicable. See 49 U.S.C 74706(c)(1)(A) and (B). RECEIVI : D), subject to individually determined rates or contracts ihat The carrier shall not make delivery of this shipment without payment of lave been agreed upon in writing between the carrier and shipper; if freight and all other lawful charges applicable, otherwise to the rates; classifications and rules that have been established by the carrier and arc available to the shipper, Shipper on""request, and to all applicable provincial and fcderal regulations. Signature SHIPPER SIGNATURE / DATE Trailer Loaded : Freight Counted : Carrier acknowledges rcccipt of packages and required This is to certify that the above named materials placards. Carrier certifies emergency response arc properly classificd, packaged, marked and By Shipper By Shipper information was made available and/or carrier has the |labeled, and are in proper condition for Driver By Driver pallets DOT emergency response guide book or equivalent 对 By documentation in the vehidic 6216-21 transportation according to the applicable said to contain 148 regulations for the DOT ByDriver / Pieces per te doen parle defectived po pod pritet Osaid Remittance AddressSendall Name & Prepaid Bills Parker Hannifin C/o Cass Information Systems P.O. Box 67 St. Louis, MO 63166"; RegexOptions options = RegexOptions.Multiline; 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