Regular Expressions 101

Save & Share

  • Regex Version: ver. 9
  • Update Regex
    ctrl+⇧+s
  • Save new 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
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

/
/

Test String

Code Generator

Generated Code

// include the latest version of the regex crate in your Cargo.toml extern crate regex; use regex::Regex; fn main() { let regex = Regex::new(r#"PublicKeyToken"(.+?)""#).unwrap(); let string = "{ <html> <head id=\"Head1\"><title> VARUNA TMS </title><link rel=\"icon\" href=\"Image/faviconvaruna.png\" type=\"Image/icon\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" /><link rel=\"Stylesheet\" href=\"Styles/Login.css\" type=\"text/css\" /><link rel=\"Stylesheet\" href=\"Styles/Popup.css\" type=\"text/css\" /> <style type=\"text/css\"> .auto-style1 { width: 191px; } .hr { margin: 0px; border-top-style: solid; border-top-width: 4px; border-top-color: #3e698c; } </style> <!-- bootstrap-css --> <link rel=\"stylesheet\" href=\"NewTheme/css/bootstrap.min.css\" /> <!-- //bootstrap-css --> <!-- Custom CSS --> <link href=\"NewTheme/css/style.css\" rel=\"stylesheet\" type=\"text/css\" /><link href=\"NewTheme/css/style-responsive.css\" rel=\"stylesheet\" /> <!-- font CSS --> <link href=\"//fonts.googleapis.com/css?family=Roboto:400,100,100italic,300,300italic,400italic,500,500italic,700,700italic,900,900italic\" rel=\"stylesheet\" type=\"text/css\" /> <!-- font-awesome icons --> <link rel=\"stylesheet\" href=\"NewTheme/css/font.css\" type=\"text/css\" /><link href=\"NewTheme/css/font-awesome.css\" rel=\"stylesheet\" /> <!-- //font-awesome icons --> </head> <body class=\"login-page-bg\" style=\"background-color:#1C2C5E\"> <div> <form method=\"post\" action=\"./Default.aspx\" onsubmit=\"javascript:return WebForm_OnSubmit();\" id=\"ctl00\"> <div class=\"aspNetHidden\"> <input type=\"hidden\" name=\"ToolkitScriptManager1_HiddenField\" id=\"ToolkitScriptManager1_HiddenField\" value=\"\" /> <input type=\"hidden\" name=\"__EVENTTARGET\" id=\"__EVENTTARGET\" value=\"\" /> <input type=\"hidden\" name=\"__EVENTARGUMENT\" id=\"__EVENTARGUMENT\" value=\"\" /> <input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\"/wEPDwUKLTI4NTM4NTI0Ng9kFgICAw9kFgICCQ8PFgIeBFRleHRlZGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgIFCWltZ0Nsb3NlMQUIaW1nQ2xvc2WPVfhvkn4jdOiHJd759Y7tqGhqIq3fQf2/QO81RZwm1Q==\" /> </div> <script type=\"text/javascript\"> //<![CDATA[ var theForm = document.forms['ctl00']; if (!theForm) { theForm = document.ctl00; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } //]]> </script> <script src=\"/vp/WebResource.axd?d=IFqQWZzjomHBbHYfmCUErI9LhfyEUSWkdxfBVysJkSXJ-G01h4DzlpjNEU3xMhBdmaMp1EcBd5y7lW7iYtSZWi0uZhEuXNbm83xxKVsPk3s1&amp;t=637454268340000000\" type=\"text/javascript\"></script> <script src=\"/vp/ScriptResource.axd?d=-ezgxAC6mtAqVr8g9PXH_olvv8kFRZVhDIchXVuXU81JArDWW3wqao3-t-TV6pNeqblXHgtFblpAds_mxi_Ts0SnRD8UxDXfEV9Ogch3ls5XcoC53hi7lvYh9VUBImOTCioih4qMLhczh6oILS7FTvf14irHHsyMWSINCP-C7wA1&amp;t=ffffffffe929205a\" type=\"text/javascript\"></script> <script src=\"/vp/ScriptResource.axd?d=LVRthHgsOS5R3nviyD_gAqpSZed1PLg2DGFLcCt0wvmCg5HyE2GsJebCbljUlJWp-Kh90XFShuYsUgM5cuLmNv1im13S78hgE3wRpsi9tVYtMUjd9VrLWylvUacc2D8M4U98yDil3UfS0mi18Hb0xQ2&amp;t=3a1336b1\" type=\"text/javascript\"></script> <script type=\"text/javascript\"> //<![CDATA[ if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-side framework failed to load.'); //]]> </script> <script src=\"/vp/ScriptResource.axd?d=T7_e20T_5J7scNgmhxZIGtxuS3XtzSusEn8lBHLnoFJWIeSJW6dBJ0UVPjrUrkuBry126RBwOz8uVzB4baRDLlpj4iimT-pleundUNycV7I2faKUjWSnDzuyZaHTOq03CkDqkuRUYr_BXk_-XRvSMA2&amp;t=3a1336b1\" type=\"text/javascript\"></script> <script src=\"/vp/Default.aspx?_TSM_HiddenField_=ToolkitScriptManager1_HiddenField&amp;_TSM_CombinedScripts_=%3b%3bAjaxControlToolkit%2c+Version%3d4.1.51116.0%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3aen-US%3afd384f95-1b49-47cf-9b47-2fa2a921a36a%3ade1feab2%3af2c8e708%3a720a52bf%3af9cec9bc%3a589eaa30%3aa67c2700%3a8613aea7%3a3202a5a2%3aab09e3fe%3a87104b7c%3abe6fb298%3a35576c48\" type=\"text/javascript\"></script> <script type=\"text/javascript\"> //<![CDATA[ function WebForm_OnSubmit() { null;if (typeof(ValidatorOnSubmit) == \"function\" && ValidatorOnSubmit() == false) return false; return true; } //]]> </script> <div class=\"aspNetHidden\"> <input type=\"hidden\" name=\"__VIEWSTATEGENERATOR\" id=\"__VIEWSTATEGENERATOR\" value=\"424327E0\" /> <input type=\"hidden\" name=\"__EVENTVALIDATION\" id=\"__EVENTVALIDATION\" value=\"/wEdAAzeoqC5L20trlG0838zf3n/ElQ7nuOGxrmM0FTFtMmIH5VRX5NO67s2WB+LguH33AiinihG6d/Xh3PZm3b5AoMQ3JuCYWkC01X2BTPzbOEVHTAOdT+RryPDGhsXl+4m+cUofI9N1jwFXVpkc0Hc3RZJIES/MI63Lb0Z0/HFNwByRYhwUCv8F/hOWciULqRcydgZRjiqyEZP34kvXGESGWks+4XXWvZyzDitv2jebLjpmYXg3tltYwyiX0M/FyTJ4OPUAufT8U+WXDkPGjTns0zi4punX0+2Of8BHcAJfJfU0Q==\" /> </div> <script type=\"text/javascript\"> //<![CDATA[ Sys.WebForms.PageRequestManager._initialize('ToolkitScriptManager1', 'ctl00', ['tUpdatePanel11','UpdatePanel11','tUpdatePanel1','UpdatePanel1'], [], [], 90, ''); //]]> </script> <br /> <div style =\"text-align:center\"> <img src=\"Image/logovarunanew.png\" style=\"width:300px;\" /> </div> <br /> <h2 style=\"color:white;text-align:center\">Transport Management System </h2> <div class=\"w3layouts-main\" style=\"width:33%; margin-top:51px; \"> <input name=\"txtUsrName\" type=\"text\" id=\"txtUsrName\" type=\"\" class=\"ggg\" name=\"Email\" placeholder=\"E-mail/Code\" required=\"\" /> <input name=\"txtPsswrd\" id=\"txtPsswrd\" type=\"password\" class=\"ggg\" name=\"Password\" placeholder=\"Password\" required=\"\" /> <span> <input type=\"checkbox\"/> Remember Me</span> <div class=\"clearfix\"> </div> <input type=\"submit\" name=\"btnLogin\" value=\"Sign In\" id=\"btnLogin\" name=\"login\" /> <div class=\"text-center\"> <span id=\"lblmsg\" style=\"color:Red;margin-top: -12px;\"></span></div> </div> <div class=\"width-35 login-page\"> <div class=\"width-10\"> <div class=\"login-box\"> <a href=\"#!\"> <i class=\"fa fa-book\"></i> <p> <a id=\"lbLogout\" href=\"javascript:__doPostBack(&#39;lbLogout&#39;,&#39;&#39;)\" style=\"color:White;\"> Knowledge</a></p> </a> </div> </div> <div class=\"width-10\"> <div class=\"login-box\"> <a id=\"lbtnForgotpassword\" href=\"javascript:__doPostBack(&#39;lbtnForgotpassword&#39;,&#39;&#39;)\" style=\"color:White;\"> <i class=\"fa fa-lock\"></i> <p> Forgot Password</p> </a> </div> </div> <div class=\"width-10\"> <div class=\"login-box\"> <a id=\"lbtnContact\" href=\"javascript:__doPostBack(&#39;lbtnContact&#39;,&#39;&#39;)\" style=\"color:White;\"> <i class=\"fa fa-phone\"></i> <p> Contact Us </p> </a> </div> </div> <div class=\"clearfix\"></div> </div> <div id=\"UpdatePanel11\"> <div id=\"pnlpop1\" style=\"width:450px;\"> <div class=\"popup\" style=\"width: 350px; height: 270px\"> <h6> <input type=\"image\" name=\"imgClose1\" id=\"imgClose1\" title=\"Close Popup\" src=\"Image/close-icon.png\" style=\"height:40px;width:40px;\" /></h6> <table> <tr> <td align=\"center\"> <b style=\"color:#3e698c\">Contact Us</b> </td> </tr> <tr> <td align=\"center\"> Corporate office : <b style=\"color:#3e698c\"> <br/> Athena Supply Chain Lab Pvt.L <br/> Plot No. 572, Sector - 37 <br/> Pace City II, Gurgaon - 122001<br/> Haryana. </b><br/> Telephone: <b style=\"color:#3e698c;\">0124 237 3215 </b><br/> Email : <b style=\"color:#3e698c;\"\">connect@athenascl.com </b><br /> Website: <b style=\"color:#3e698c;\"\">:www.athenascl.com<b></b> </td> </tr> </table> </div> </div> </div> <div id=\"UpdatePanel1\"> <div id=\"pnlpop\" style=\"width:450px;\"> <div class=\"popup\" style=\"width: 450px; height: 280px\"> <h6> <input type=\"image\" name=\"imgClose\" id=\"imgClose\" title=\"Close Popup\" src=\"Image/close-icon.png\" style=\"height:40px;width:40px;\" /></h6> <table align=\"center\"> <tr> <td align=\"center\"> <b style=\"color:#3e698c\">Forgot Password</b> </td> </tr> <tr> <td align=\"center\"> <input name=\"txtEmailID\" type=\"text\" id=\"txtEmailID\" placeholder=\"E-MAIL\" style=\"width:250px;\" /> <input type=\"hidden\" name=\"twm3_ClientState\" id=\"twm3_ClientState\" /> <span id=\"rfv3\" style=\"color:Red;display:none;\">*</span> <span id=\"rev\" style=\"color:Red;font-size:Small;display:none;\">Invalid Email Id</span> </td> </tr> <tr> <td></td> </tr> <tr> <td valign=\"top\" align=\"center\"> <input type=\"submit\" name=\"btlFSubmit\" value=\"Submit\" onclick=\"javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;btlFSubmit&quot;, &quot;&quot;, true, &quot;fpswrd&quot;, &quot;&quot;, false, false))\" id=\"btlFSubmit\" /> </td> </tr> </table> </div> </div> </div> <script type=\"text/javascript\"> //<![CDATA[ var Page_Validators = new Array(document.getElementById(\"rfv3\"), document.getElementById(\"rev\")); //]]> </script> <script type=\"text/javascript\"> //<![CDATA[ var rfv3 = document.all ? document.all[\"rfv3\"] : document.getElementById(\"rfv3\"); rfv3.controltovalidate = \"txtEmailID\"; rfv3.focusOnError = \"t\"; rfv3.errormessage = \"*\"; rfv3.display = \"Dynamic\"; rfv3.validationGroup = \"fpswrd\"; rfv3.evaluationfunction = \"RequiredFieldValidatorEvaluateIsValid\"; rfv3.initialvalue = \"\"; var rev = document.all ? document.all[\"rev\"] : document.getElementById(\"rev\"); rev.controltovalidate = \"txtEmailID\"; rev.errormessage = \"Invalid Email Id\"; rev.display = \"Dynamic\"; rev.validationGroup = \"fpswrd\"; rev.evaluationfunction = \"RegularExpressionValidatorEvaluateIsValid\"; rev.validationexpression = \"\\\\w+([-+.\\']\\\\w+)*@\\\\w+([-.]\\\\w+)*\\\\.\\\\w+([-.]\\\\w+)*\"; //]]> </script> <script type=\"text/javascript\"> //<![CDATA[ (function() {var fn = function() {$get(\"ToolkitScriptManager1_HiddenField\").value = '';Sys.Application.remove_init(fn);};Sys.Application.add_init(fn);})(); var Page_ValidationActive = false; if (typeof(ValidatorOnLoad) == \"function\") { ValidatorOnLoad(); } function ValidatorOnSubmit() { if (Page_ValidationActive) { return ValidatorCommonOnSubmit(); } else { return true; } } Sys.Application.add_init(function() { $create(Sys.Extended.UI.ModalPopupBehavior, {\"BackgroundCssClass\":\"mdlbgrgnd\",\"CancelControlID\":\"imgClose1\",\"Drag\":true,\"PopupControlID\":\"pnlpop1\",\"PopupDragHandleControlID\":\"pnlpop1\",\"dynamicServicePath\":\"/vp/Default.aspx\",\"id\":\"mpefp1\"}, null, null, $get(\"lbtnContact\")); }); Sys.Application.add_init(function() { $create(Sys.Extended.UI.TextBoxWatermarkBehavior, {\"ClientStateFieldID\":\"twm3_ClientState\",\"WatermarkCssClass\":\"watermark\",\"WatermarkText\":\"Email Id\",\"id\":\"twm3\"}, null, null, $get(\"txtEmailID\")); }); document.getElementById('rfv3').dispose = function() { Array.remove(Page_Validators, document.getElementById('rfv3')); } document.getElementById('rev').dispose = function() { Array.remove(Page_Validators, document.getElementById('rev')); } Sys.Application.add_init(function() { $create(Sys.Extended.UI.ModalPopupBehavior, {\"BackgroundCssClass\":\"mdlbgrgnd\",\"CancelControlID\":\"imgClose\",\"Drag\":true,\"PopupControlID\":\"pnlpop\",\"PopupDragHandleControlID\":\"pnlpop\",\"dynamicServicePath\":\"/vp/Default.aspx\",\"id\":\"mpefp\"}, null, null, $get(\"lbtnForgotpassword\")); }); //]]> </script> </form> <script src=\"js/bootstrap.js\"></script> </div> </body> </html> }"; // result will be a tuple containing the start and end indices for the first match in the string let result = regex.captures(string); let (start, end) = match result { Some((s, e)) => (s, e), None => { // ... } }; println!("{}", &string[start, end]); }

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 Rust, please visit: https://docs.rs/regex/latest/regex/