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

/
/
gmis

Test String

Code Generator

Generated Code

$re = '/<multiline label="Description">\s<p>.*<\/p>\s<p>(?\'welcomeLine\'.+)<\/p>.*<tr class="odd">\s<td>(?\'case_id\'\d+)<\/td>\s<td>\s(?\'status\'\w+)\s<\/td>\s<td>(?\'case_date\'[a-z\s0-9,]+)<\/td>\s<td>(?\'amount\'[0-9.]+)<\/td>\s<td>(?\'descriptor\'[a-z0-9.\s]+).*/mis'; $str = '"<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=320, target-densitydpi=device-dpi"> <style type="text/css"> /* Mobile-specific Styles */ @media only screen and (max-width: 660px) { table[class=w0],td[class=w0] { width: 0 !important; } table[class=w10],td[class=w10],img[class=w10] { width: 10px !important; } table[class=w15],td[class=w15],img[class=w15] { width: 15px !important; } table[class=w30],td[class=w30],img[class=w30] { width: 10px !important; } table[class=w60],td[class=w60],img[class=w60] { width: 10px !important; } table[class=w125],td[class=w125],img[class=w125] { width: 80px !important; } table[class=w130],td[class=w130],img[class=w130] { width: 55px !important; } table[class=w140],td[class=w140],img[class=w140] { width: 90px !important; } table[class=w160],td[class=w160],img[class=w160] { width: 180px !important; } table[class=w170],td[class=w170],img[class=w170] { width: 100px !important; } table[class=w180],td[class=w180],img[class=w180] { width: 80px !important; } table[class=w195],td[class=w195],img[class=w195] { width: 80px !important; } table[class=w220],td[class=w220],img[class=w220] { width: 80px !important; } table[class=w240],td[class=w240],img[class=w240] { width: 180px !important; } table[class=w255],td[class=w255],img[class=w255] { width: 185px !important; } table[class=w275],td[class=w275],img[class=w275] { width: 135px !important; } table[class=w280],td[class=w280],img[class=w280] { width: 135px !important; } table[class=w300],td[class=w300],img[class=w300] { width: 140px !important; } table[class=w325],td[class=w325],img[class=w325] { width: 95px !important; } table[class=w360],td[class=w360],img[class=w360] { width: 140px !important; } table[class=w410],td[class=w410],img[class=w410] { width: 180px !important; } table[class=w470],td[class=w470],img[class=w470] { width: 200px !important; } table[class=w580],td[class=w580],img[class=w580] { width: 280px !important; } table[class=w640],td[class=w640],img[class=w640] { width: 300px !important; } table[class *=hide],td[class *=hide],img[class *=hide],p[class *=hide],span[class *=hide] { display: none !important; } table[class=h0],td[class=h0] { height: 0 !important; } .article-content,#left-sidebar { -webkit-text-size-adjust: 90% !important; -ms-text-size-adjust: 90% !important; } img { height: auto; line-height: 100%; } } /* Client-specific Styles */ #outlook a { padding: 0; } /* Force Outlook to provide a "view in browser" button. */ body { width: 100% !important; } /* Force Hotmail to display emails at full width */ /* Reset Styles */ /* Add 100px so mobile switch bar doesn\'t cover street address. */ body { background-color: #ececec; margin: 0; padding: 0; } img { outline: none; text-decoration: none; display: block; } br,strong br,b br,em br,i br { line-height: 100%; } h1,h2,h3,h4,h5,h6 { line-height: 100% !important; -webkit-font-smoothing: antialiased; } h1 a,h2 a,h3 a,h4 a,h5 a,h6 a { color: blue !important; } h1 a:active,h2 a:active,h3 a:active,h4 a:active,h5 a:active,h6 a:active { color: red !important; } /* Preferably not the same color as the normal header link color. There is limited support for psuedo classes in email clients, this was added just for good measure. */ h1 a:visited,h2 a:visited,h3 a:visited,h4 a:visited,h5 a:visited,h6 a:visited { color: purple !important; } /* Preferably not the same color as the normal header link color. There is limited support for psuedo classes in email clients, this was added just for good measure. */ table td,table tr { border-collapse: collapse; } /* Body text color for the New Yahoo. This example sets the font of Yahoo\'s Shortcuts to black. */ /* This most probably won\'t work in all email clients. Don\'t include code blocks in email. */ code { white-space: normal; word-break: break-all; } #background-table { background-color: #ececec; } /* Webkit Elements */ #footer { border-radius: 0px 0px 6px 6px; -moz-border-radius: 0px 0px 6px 6px; -webkit-border-radius: 0px 0px 6px 6px; -webkit-font-smoothing: antialiased; letter-spacing: 0.2px; margin-top: 30px; border-top: 1px solid #555; border-color: rgba(255, 255, 255, 0.15); background-color: #292929; color: #e2e2e2; } #footer a { color: #e7cba3; text-decoration: none; font-weight: bold; } #footer .block .content { padding: 0.5em 0; margin-top: 0; } #footer p { font-family: \'Helvetica Neue\', Arial, Helvetica, Geneva, sans-serif; font-size: 12px; color: rgba(255, 255, 255, 0.65); margin: 0 0 1.2em; display: block; -webkit-margin-before: 1em; -webkit-margin-after: 1em; -webkit-margin-start: 0px; -webkit-margin-end: 0px; } #footer-right { background-color: #292929; border-radius: 0px 0px 6px 0px; -moz-border-radius: 0px 0px 6px 0px; -webkit-border-radius: 0px 0px 6px 0px; -webkit-font-smoothing: antialiased; } #footer-wrapper { color: silver; color: rgba(255, 255, 255, 0.65); font-size: 0.857em; } #header { border-radius: 6px 6px 0px 0px; -moz-border-radius: 6px 6px 0px 0px; -webkit-border-radius: 6px 6px 0px 0px; -webkit-font-smoothing: antialiased; background-color: #48a9e4; background-image: -moz-linear-gradient(top, #0779bf 0%, #48a9e4 100%); background-image: -ms-linear-gradient(top, #0779bf 0%, #48a9e4 100%); background-image: -o-linear-gradient(top, #0779bf 0%, #48a9e4 100%); background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, #0779bf), color-stop(1, #48a9e4) ); background-image: -webkit-linear-gradient(top, #0779bf 0%, #48a9e4 100%); background-image: linear-gradient(top, #0779bf 0%, #48a9e4 100%); width: 640px; height: 74px; cellpadding: 0; cellspacing: 0; border: 0; } /* Fonts and Content */ .article-content { font-size: 13px; line-height: 18px; color: #444444; margin-top: 0px; margin-bottom: 18px; font-family: \'Helvetica Neue\', Arial, Helvetica, sans-serif; } .article-content p { margin-bottom: 15px; } .datagrid table { border-collapse: collapse; text-align: left; width: 100%; } .datagrid { font: normal 12px/150% Arial, Helvetica, sans-serif; background: #fff; overflow: hidden; border: 1px solid #757575; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; } .datagrid table td,.datagrid table th { padding: 3px 10px; } .datagrid table thead th { background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #757575 ), color-stop(1, #757575) ); background: -moz-linear-gradient(center top, #757575 5%, #757575 100%); filter: progid : DXImageTransform.Microsoft.gradient ( startColorstr = \'#757575\', endColorstr = \'#757575\' ); background-color: #757575; color: #FFFFFF; font-size: 15px; font-weight: bold; #text-shadow: 0 1px 0 #FFFFFF; border-left: 1px solid #FFFFFF; } .datagrid table thead th:first-child { border: none; } .datagrid table tbody td { color: #7D7D7D; border-left: 1px solid #DBDBDB; font-size: 12px; font-weight: normal; } .datagrid table tbody .odd td { background: #DDDDDD; color: #666666; border: 1px solid #FFFFFF; } .datagrid table tbody .even td { background: #F2F2F2; color: #666666; border: 1px solid #FFFFFF; } .datagrid table tbody td:first-child { border-left: none; } .datagrid table tbody tr:last-child td { border-bottom: none; } </style> </head> <body> <table width="100%" cellpadding="0" cellspacing="0" border="0" id="background-table"> <tbody> <tr> <td align="center" bgcolor="#ececec"> <table class="w640" style="margin: 0 10px;" width="640" cellpadding="0" cellspacing="0" border="0"> <tbody> <tr> <td class="w640" width="640" height="20"></td> </tr> <tr> <td class="w640" width="640"> <table id="header" class="w640"> <tbody> <tr> <td width="20"></td> <td width="307" height="100"> <div align="left" style="text-align: left"> <img id="customHeaderImage" label="Header Image" editable="true" width="307" src="https://my.cdrn.com/themes/bartik/images/email/header_cdrn_logo.png" class="w640" border="0" align="top" style="display: inline"> </div></td> <td class="hide w0" width="313"></td> </tr> </tbody> </table></td> </tr> <tr> <td class="w640" width="640" height="15" bgcolor="#ffffff"></td> </tr> <tr id="simple-content-row"> <td class="w640" width="640" bgcolor="#ffffff"> <table class="w640" width="640" cellpadding="0" cellspacing="0" border="0"> <tbody> <tr> <td class="w30" width="30"></td> <td class="w580" width="580"><layout label="Text only"> <table class="w580" width="580" cellpadding="0" cellspacing="0" border="0"> <tbody> <tr> <td class="w580" width="580"> <div align="left" class="article-content"> <multiline label="Description"> <p>Dear PDFFiller, INC,</p> <p>This notice is to inform you that the following new CDRN case has been created since 2020-10-01 16:49:06 UTC.</p> <p> <fieldset> <legend>NEW CASES</legend> <div class="datagrid"> <table> <thead> <tr> <th>Case ID</th> <th>Current Status</th> <th>Case Date</th> <th>Amount</th> <th>Descriptor</th> <th>Descriptor Contact</th> </tr> </thead> <tbody> <tr class="odd"> <td>289070923</td> <td> PENDING </td> <td>Sep 30, 2020</td> <td>144</td> <td>PDFD.CO 7787453075</td> <td></td> </tr> </tbody> </table> </div> </fieldset> </p> <p>Please visit https://my.cdrn.com and process your case within 72 hours or the case will be automatically declined and you will receive a chargeback from the Card Issuer for the customer dispute.</p> <p>Sincerely,</p> <p> <div>Client Support</div> <div>Support@Verifi.com</div> </p> </multiline> </div> </td> </tr> <tr> <td class="w580" width="580" height="10"></td> </tr> </tbody> </table> </layout> </tr> </tbody> </table></td> </tr> <tr> <td id="footer" class="w640" width="640" height="58"> <table class="w640" width="640" height="58" cellpadding="0" cellspacing="0" border="0"> <tbody> <tr> <td width="30"></td> <td class="w580" width="580" valign="top"> <div id="footer-wrapper"> <div class="section"> <div id="footer" class="clearfix"> <div class="region region-footer"> <div id="block-block-1" class="block block-block"> <div class="content"> <p>Copyright &#169; 2,020 CDRN, Cardholder Dispute Resolution Network. All rights reserved.</p> </div> </div> </div> </div> </div> </div></td> <td width="30" id="footer-right"></td> </tr> </tbody> </table> </td> </tr> <tr> <td class="w640" width="640" height="60"></td> </tr> </tbody> </table></td> </tr> </tbody> </table> </body> </html>" '; 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