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

/
/
gsi

Test String

Code Generator

Generated Code

using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string pattern = @"^(?:(?:(?!table).)*table){19}(.+?(?=table))"; string input = @"<HTML><HEAD><TITLE>Purchase order: PSD00592</TITLE><link id=""cssref"" rel=""stylesheet"" type=""text/css"" href=""IE5BIRCHST08.css""> <meta http-equiv=""Content-Type"" content=""text/html; charset=UTF-8""> </HEAD><BODY><TABLE width=98% border=""1"" align=center><tr><td><form name='doclife'><input type='hidden' name='doccycle' value=108891162271488190605350.1266cosbor|536|328></form><TABLE width=100% cellSpacing=0 <tr><td colspan=""2"" align=""center""><font size=4><b>PURCHASE ORDER</b></td></tr><tr><td colspan=""2"" align=""center""><font size=3><b>Pendry San Diego </b></td></tr><tr><td colspan=""2"" align=""center""><font size=""2""><b>RGC Gaslamp LLC</b></td></tr><tr><td colspan=""2"" align=""center""><font size=""2""><i>Montage Hotels & Resorts Marketplace</i></td></tr><tr style=""height=.1""><td colspan=""2"" align=""center""><HR></td></tr><tr><td align=""left""><font size=""2""><b>PO NUMBER : </b>PSD00592</td><TD align=""left""><font size=""2""><b>Status: </b>Fax/email/csv accepted</TD></tr><tr><td align=""left""><font size=2 ><b>Delivery date : </b>02/27/2017</font></td><TD align=""left""><font size=""2""><b>PO Submit Date: </b>02/27/2017 02:17:00</TD></tr><tr><td><font size=""2""><b>Customer Account #: </b></font></td></tr><tr><td> <font size=""2""><b>PO Type: </b>Standard</font></td></tr><tr><td align=""left""><font size=""2""><b>Purchase type : </b>Food</td><TD align=""left""><font size=""2""></TD></tr> <tr style=""height=.1""><td colspan=2><hr></td></tr> <tr> <td align=""left"" valign=""top""><font size=""2""><b>Supplier:</b> &nbsp;SPECIALTY PRODUCE(On the Fly)</font> <table> <tr><td colspan=2><font size=""2"">1929 Hancock st</td></tr> <tr><td colspan=2><font size=""2"">Suite 150</td></tr> <tr><td colspan=2><font size=""2"">san diego, CA, 92110</td></tr> <tr><td colspan=2><font size=""2""><b>Attn:</b> Matt Preston </td></tr> <tr><td><font size=""2""><b>Title:</b> </td><td><font size=""2""></td></tr> <tr><td><font size=""2""><b>Phone:</b> </td><td><font size=""2"">6192470394</td></tr> <tr><td><font size=""2""><b>Fax:</b> </td><td><font size=""2""></td></tr> <tr><td><font size=""2""><b>Email:</b> </td><td ><font size=""2"">ordersnext@specialtyproduce.com</td></tr> <tr><td><font size=""2""><b>DBA:</b> </td><td><font size=""2""></td></tr> </table> </td> <td align=""left"" valign=""top""><b><font size=""2"">Bill To:</b> &nbsp;Pendry San Diego</font> <table> <tr><td><font size=""2"">P.O. Box 52031</td></tr> <tr><td><font size=""2"">Phoenix, AZ, 85072, US</td></tr> <tr><td><font size=""2""><b>Attn: </b>Montage Hotels & Resorts</td></tr> </table> <table><tr><td>&nbsp</td></tr></table> <font size=""2""><b>Ship To: </b> &nbsp;Pendry San Diego</font> <table > <tr><td><font size=""2"">550 J Street</td></tr> <tr><td><font size=""2"">San Diego, CA, 92101, US</b></td></tr> <tr><td><font size=""2""><b>Attn:</b> Christopher Osborne</b></td></tr> </table> </td> <tr style=""height=.1""><td colspan=2><hr></td></tr> <tr> <td align=""left""><font size=""2""><b>Sent From: &nbsp;</b>Pendry San Diego</font> <table > <tr><td><font size=""2""><b>Name: </b></td><td><font size=""2"">Christopher Osborne</td></tr> <tr><td><font size=""2""><b>Phone: </b></td><td><font size=""2"">(949) 715-5000</td></tr> <tr><td><font size=""2""><b>Fax: </b></td><td><font size=""2""></td></tr> <tr><td><font size=""2""><b>Email: </b></td><td ><font size=""2"">cosborne@pendryhotels.com</td></tr> <tr><td><font size=""2""><b>Cost Center: </b></td><td><font size=""2""></td></tr> </table> </td> <td align=""left"" valign=""top""><font size=""2""><b>Terms: </b> <table > <tr><td colspan=2><font size=""2""><b>Subject: </b></td><td><font size=""2"">Provisional order</td></tr> <tr><td colspan=2><font size=""2""><b>Partial Order Accepted: </b></td><td><font size=""2"">No</td></tr> <tr><td colspan=2><font size=""2""><b>Ship via: </b></td><td width = 140><font size=""2"">Best Way</td></tr> <tr><td colspan=2><font size=""2""><b>Payment Terms: </b></td><td><font size=""2"">Net 30 Days (description)</td></tr> <tr id=dept><td colspan=2><font size=""2""><b>Department: </b></td><td><font size=""2"">50-205-Provisional</td></tr> <tr><td colspan=2><font size=""2""><b>Payment method: </b></td><td><font size=""2"">Purchase order</td></tr> </table> </td> </tr> <tr style=""height=.1""><td colspan=2><hr></td></tr> <table><tr><td> <b><font size=""2""><b>Notes and Attachments :</b> </td><td id='hide' style=""visibility:hidden;position:absolute""><div name='Button' ><font color=""#003399"">&nbsp&nbsp&nbspShow Line Notes<input type = checkbox name = ""showInlineNotes"" value=""ON"" onclick=""ShowLineNotes(this,0)""></font></div></td></tr></table> <table width=100%> <tr><tr><td><font size=2><b> Header Notes :</b></font></td></tr><tr><td><font size=2>No Notes</font></td></tr> <td><font size=2>This Purchase Order has <b>0</b> Attachments</font></td> </tr> </table> </td> </tr> <tr> <td colspan=2> <table width=100% align=center cellspacing=""0""> <tr><td ><font size=""2""><b>#</b></td><td ><font size=""2""><b>Item SKU</b></td><td ><font size=""2""><b>Product Desc.</b></td><td align=right><font size=""2""><b>Qty</b></td><td align=center><font size=""2""><b>UOM</b></td><td align=right><font size=""2""><b>Price</b></td><td align=right><font size=""2""><b>Extension</b></td></tr> <tr><td VALIGN =baseline><font size=""2"">1</td><td VALIGN =baseline width = 100 style=font-size:10pt>022 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Bananas</td><td VALIGN =baseline align=right style=font-size:10pt>0.50</td><td VALIGN =baseline align=center style=font-size:10pt>CS</td><td VALIGN =baseline align=right style=font-size:10pt>$24.8000</td><td VALIGN =baseline align=right><font size=""2"">$12.40</td> <tr><td VALIGN =baseline><font size=""2"">2</td><td VALIGN =baseline width = 100 style=font-size:10pt>056 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Berries Strawberry</td><td VALIGN =baseline align=right style=font-size:10pt>0.50</td><td VALIGN =baseline align=center style=font-size:10pt>CS</td><td VALIGN =baseline align=right style=font-size:10pt>$24.2000</td><td VALIGN =baseline align=right><font size=""2"">$12.10</td> <tr><td VALIGN =baseline><font size=""2"">3</td><td VALIGN =baseline width = 100 style=font-size:10pt>085 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Cheese Burrata DiStefano</td><td VALIGN =baseline align=right style=font-size:10pt>1.00</td><td VALIGN =baseline align=center style=font-size:10pt>CS</td><td VALIGN =baseline align=right style=font-size:10pt>$28.5000</td><td VALIGN =baseline align=right><font size=""2"">$28.50</td> <tr><td VALIGN =baseline><font size=""2"">4</td><td VALIGN =baseline width = 100 style=font-size:10pt>082 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Cheese Pecorino Toscano DOP Aged 6 mo.</td><td VALIGN =baseline align=right style=font-size:10pt>6.00</td><td VALIGN =baseline align=center style=font-size:10pt>LB</td><td VALIGN =baseline align=right style=font-size:10pt>$9.5800</td><td VALIGN =baseline align=right><font size=""2"">$57.48</td> <tr><td VALIGN =baseline><font size=""2"">5</td><td VALIGN =baseline width = 100 style=font-size:10pt>078 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Dairy Yogurt Plain Organic Clover</td><td VALIGN =baseline align=right style=font-size:10pt>3.00</td><td VALIGN =baseline align=center style=font-size:10pt>TUB</td><td VALIGN =baseline align=right style=font-size:10pt>$5.4000</td><td VALIGN =baseline align=right><font size=""2"">$16.20</td> <tr><td VALIGN =baseline><font size=""2"">6</td><td VALIGN =baseline width = 100 style=font-size:10pt>087 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>FM Herbs Sorrel Wood - Coleman Family Farm</td><td VALIGN =baseline align=right style=font-size:10pt>2.00</td><td VALIGN =baseline align=center style=font-size:10pt>BU</td><td VALIGN =baseline align=right style=font-size:10pt>$3.7500</td><td VALIGN =baseline align=right><font size=""2"">$7.50</td> <tr><td VALIGN =baseline><font size=""2"">7</td><td VALIGN =baseline width = 100 style=font-size:10pt>036 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>FM Passionfruit - Koral's Tropical Fruit Farm</td><td VALIGN =baseline align=right style=font-size:10pt>3.00</td><td VALIGN =baseline align=center style=font-size:10pt>LB</td><td VALIGN =baseline align=right style=font-size:10pt>$8.5000</td><td VALIGN =baseline align=right><font size=""2"">$25.50</td> <tr><td VALIGN =baseline><font size=""2"">8</td><td VALIGN =baseline width = 100 style=font-size:10pt>092 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>FM Radish Long Scarlet - Valdivia Farm</td><td VALIGN =baseline align=right style=font-size:10pt>5.00</td><td VALIGN =baseline align=center style=font-size:10pt>BU</td><td VALIGN =baseline align=right style=font-size:10pt>$2.5000</td><td VALIGN =baseline align=right><font size=""2"">$12.50</td> <tr><td VALIGN =baseline><font size=""2"">9</td><td VALIGN =baseline width = 100 style=font-size:10pt>093 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>FM Radish Watermelon - Black Sheep Produce</td><td VALIGN =baseline align=right style=font-size:10pt>5.00</td><td VALIGN =baseline align=center style=font-size:10pt>BU</td><td VALIGN =baseline align=right style=font-size:10pt>$2.2500</td><td VALIGN =baseline align=right><font size=""2"">$11.25</td> <tr><td VALIGN =baseline><font size=""2"">10</td><td VALIGN =baseline width = 100 style=font-size:10pt>003 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Fresh Micro Radish Mix</td><td VALIGN =baseline align=right style=font-size:10pt>2.00</td><td VALIGN =baseline align=center style=font-size:10pt>CRT</td><td VALIGN =baseline align=right style=font-size:10pt>$11.9500</td><td VALIGN =baseline align=right><font size=""2"">$23.90</td> <tr><td VALIGN =baseline><font size=""2"">11</td><td VALIGN =baseline width = 100 style=font-size:10pt>007 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Fresh-Clams Venus</td><td VALIGN =baseline align=right style=font-size:10pt>5.00</td><td VALIGN =baseline align=center style=font-size:10pt>LB</td><td VALIGN =baseline align=right style=font-size:10pt>$3.9500</td><td VALIGN =baseline align=right><font size=""2"">$19.75</td> <tr><td VALIGN =baseline><font size=""2"">12</td><td VALIGN =baseline width = 100 style=font-size:10pt>017 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Herbs Parsley Reg bunch</td><td VALIGN =baseline align=right style=font-size:10pt>12.00</td><td VALIGN =baseline align=center style=font-size:10pt>BU</td><td VALIGN =baseline align=right style=font-size:10pt>$0.2500</td><td VALIGN =baseline align=right><font size=""2"">$3.00</td> <tr><td VALIGN =baseline><font size=""2"">13</td><td VALIGN =baseline width = 100 style=font-size:10pt>069 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Lett Boston Hydroponic</td><td VALIGN =baseline align=right style=font-size:10pt>1.00</td><td VALIGN =baseline align=center style=font-size:10pt>CS</td><td VALIGN =baseline align=right style=font-size:10pt>$27.8500</td><td VALIGN =baseline align=right><font size=""2"">$27.85</td> <tr><td VALIGN =baseline><font size=""2"">14</td><td VALIGN =baseline width = 100 style=font-size:10pt>094 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Local- Root Turnips Pink - JF Organic Farms</td><td VALIGN =baseline align=right style=font-size:10pt>8.00</td><td VALIGN =baseline align=center style=font-size:10pt>BU</td><td VALIGN =baseline align=right style=font-size:10pt>$2.2500</td><td VALIGN =baseline align=right><font size=""2"">$18.00</td> <tr><td VALIGN =baseline><font size=""2"">15</td><td VALIGN =baseline width = 100 style=font-size:10pt>079 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Local- Wood Fig - Murray Family Farm</td><td VALIGN =baseline align=right style=font-size:10pt>10.00</td><td VALIGN =baseline align=center style=font-size:10pt>LB</td><td VALIGN =baseline align=right style=font-size:10pt>$1.1700</td><td VALIGN =baseline align=right><font size=""2"">$11.70</td> <tr><td VALIGN =baseline><font size=""2"">16</td><td VALIGN =baseline width = 100 style=font-size:10pt>057 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Melons Cantelope</td><td VALIGN =baseline align=right style=font-size:10pt>3.00</td><td VALIGN =baseline align=center style=font-size:10pt>EA</td><td VALIGN =baseline align=right style=font-size:10pt>$3.1000</td><td VALIGN =baseline align=right><font size=""2"">$9.30</td> <tr><td VALIGN =baseline><font size=""2"">17</td><td VALIGN =baseline width = 100 style=font-size:10pt>020 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Mush Hon Shimeji (Brown Beech)</td><td VALIGN =baseline align=right style=font-size:10pt>1.00</td><td VALIGN =baseline align=center style=font-size:10pt>CS</td><td VALIGN =baseline align=right style=font-size:10pt>$42.5000</td><td VALIGN =baseline align=right><font size=""2"">$42.50</td> <tr><td VALIGN =baseline><font size=""2"">18</td><td VALIGN =baseline width = 100 style=font-size:10pt>027 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Mush Maitake USA</td><td VALIGN =baseline align=right style=font-size:10pt>1.00</td><td VALIGN =baseline align=center style=font-size:10pt>CS</td><td VALIGN =baseline align=right style=font-size:10pt>$42.5000</td><td VALIGN =baseline align=right><font size=""2"">$42.50</td> <tr><td VALIGN =baseline><font size=""2"">19</td><td VALIGN =baseline width = 100 style=font-size:10pt>059 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Pineapple Large</td><td VALIGN =baseline align=right style=font-size:10pt>0.50</td><td VALIGN =baseline align=center style=font-size:10pt>CS</td><td VALIGN =baseline align=right style=font-size:10pt>$16.4500</td><td VALIGN =baseline align=right><font size=""2"">$8.23</td> <tr><td VALIGN =baseline><font size=""2"">20</td><td VALIGN =baseline width = 100 style=font-size:10pt>013 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Tom Chry Heirlm Mix Mini</td><td VALIGN =baseline align=right style=font-size:10pt>1.00</td><td VALIGN =baseline align=center style=font-size:10pt>CS</td><td VALIGN =baseline align=right style=font-size:10pt>$25.7500</td><td VALIGN =baseline align=right><font size=""2"">$25.75</td> <tr><td VALIGN =baseline><font size=""2"">21</td><td VALIGN =baseline width = 100 style=font-size:10pt>117 *</td><td VALIGN =baseline width = 200 style=font-size:10pt>Tomatillos</td><td VALIGN =baseline align=right style=font-size:10pt>1.00</td><td VALIGN =baseline align=center style=font-size:10pt>CS</td><td VALIGN =baseline align=right style=font-size:10pt>$7.5000</td><td VALIGN =baseline align=right><font size=""2"">$7.50</td> <tr><td colspan=12 align=center><font size=""2""><hr></td></tr> <tr><td colspan=4><b><font size=""2"">* - Non catalog item</fond></td></tr> <tr><td colspan=4 align=right><b><font size=""2"">Sub Total:</b></td><td></td><td></td><td align=right><font size=""2"">$423.41</td></tr> <tr><td colspan=4 align=right><b><font size=""2"">Freight:</b></td><td></td><td></td><td align=right><font size=""2"">$0.00</td></tr> <tr><td colspan=4 align=right><b><font size=""2"">Tax Amount:</b></td><td></td><td></td><td align=right><font size=""2"">$0.00</td></tr> <tr><td colspan=4 align=right><b><font size=""2"">Less Discount:</b></td><td></td><td></td><td align=right><font size=""2"">$0.00</td></tr> <tr><td colspan=4 align=right><b><font size=""2"">Total amount due:</b></td><td></td><td></td><td align=right><font size=""2"">$423.41</td></tr> </table> <font size=""1""> </font> </td> </tr></td></tr></table> </BODY></HTML>"; RegexOptions options = RegexOptions.Singleline | RegexOptions.IgnoreCase; 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