Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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"(<b>Name)(.*?<b>)").unwrap(); let string = "<html> <head> <meta http-equiv=\"Content-Language\" content=\"en-us\"> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\"> <meta name=\"GENERATOR\" content=\"Microsoft FrontPage 4.0\"> <meta name=\"ProgId\" content=\"FrontPage.Editor.Document\"> <title>Member Card The Institute of Chartered Accountants of India</title> <script language=\"javascript\" type=\"text/javascript\"> <!-- var win=null; function NewWindow(mypage,myname,w,h,scroll,pos){ if(pos==\"random\"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;} if(pos==\"center\"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;} else if((pos!=\"center\" && pos!=\"random\") || pos==null){LeftPosition=0;TopPosition=20} settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no'; win=window.open(mypage,myname,settings);} // --> </script> <SCRIPT LANGUAGE=\"JavaScript1.1\"> <!-- Original: Vivek Gupta --> <!-- Begin function right(e) { if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) return false; else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) { alert(\"Sorry, you do not have permission to right click.\"); return false; } return true; } document.onmousedown=right; document.onmouseup=right; if (document.layers) window.captureEvents(Event.MOUSEDOWN); if (document.layers) window.captureEvents(Event.MOUSEUP); window.onmousedown=right; window.onmouseup=right; // End --> </script> </head> <body bgcolor=\"#ECFFFF\"> <p align=\"center\"><u><i><b><font size=\"5\">Members Details as on Date</font></b></i></u></p> <hr> <div align=\"right\"> <table border=\"0\" width=\"100%\"> <tr> <td width=\"13%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Membership No.</b></font></td> <td width=\"2%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>:</b></font></td> <td width=\"25%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>140337,&nbsp;&nbsp;&nbsp; </b></font><b><font color=\"#FF0000\" size=\"3\">ACTIVE</font> </b></td> <td width=\"8%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Sex</b></font></td> <td width=\"1%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>:</b></font></td> <td width=\"18%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>M </b></font></td> <td width=\"13%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Date of Birth</b></font></td> <td width=\"1%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>:</b></font></td> <td width=\"38%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>30/12/1986 </b></font></td> </tr> <tr> <td width=\"13%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Name</b></font></td> <td width=\"2%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>:</b></font></td> <td width=\"25%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>CA. THAKRAR UTSAV SUBHASH </b></font></td> <td width=\"8%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Blood Grp</b></font></td> <td width=\"1%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>:</b></font></td> <td width=\"18%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>B (-) </b></font></td> <td width=\"13%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Enrolment Dt.</b></font></td> <td width=\"1%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>:</b></font></td> <td width=\"38%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>29/07/2011 </b></font></td> </tr> <tr> <td width=\"13%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Asso.&nbsp; / Fellow</b></font></td> <td width=\"2%\" bgcolor=\"#99CCFF\">:</td> <td width=\"25%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>ACA </b></font></td> <td width=\"8%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Nationality</b></font></td> <td width=\"1%\" bgcolor=\"#99CCFF\"></td> <td width=\"18%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>IND </b></font></td> <td width=\"13%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Fellow Date</b></font></td> <td width=\"1%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>:</b></font></td> <td width=\"38%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>&nbsp; </b></font></td> </tr> <tr> <td width=\"13%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Father's Name</b></font></td> <td width=\"2%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>:</b></font></td> <td width=\"25%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>SUBHASH THAKRAR </b></font></td> <td width=\"8%\" bgcolor=\"#CCCCFF\"></td> <td width=\"1%\" bgcolor=\"#99CCFF\"></td> <td width=\"18%\" bgcolor=\"#99CCFF\"></td> <td width=\"13%\" bgcolor=\"#CCCCFF\"><b><font size=\"2\">COP Status</font></b></td> <td width=\"1%\" bgcolor=\"#99CCFF\"><b>:</b></td> <td width=\"27%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>FULLTIME </b></font></td> </tr> </table> </div> <hr> <div align=\"right\"> <table border=\"0\" width=\"100%\"> <tr> <td width=\"50%\" colspan=\"2\" bgcolor=\"#CCCCFF\"><u><font size=\"2\"><b>Professional Address Details</b></font></u></td> <td width=\"50%\" colspan=\"2\" bgcolor=\"#CCCCFF\"><u><font size=\"2\"><b>Residential Address Details</b></font></u></td> </tr> <tr> <td width=\"50%\" colspan=\"2\"></td> <td width=\"50%\" colspan=\"2\"></td> </tr> <tr> <td width=\"50%\" colspan=\"2\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>OPP PUNJAB NATIONAL BANK </b></font></td> <td width=\"50%\" colspan=\"2\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>M/S CHATRABHUJ SAVJI &amp; CO </b></font></td> </tr> <tr> <td width=\"50%\" colspan=\"2\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>SUTARWADA </b></font></td> <td width=\"50%\" colspan=\"2\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>SUTARWADA </b></font></td> </tr> <tr> <td width=\"50%\" colspan=\"2\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>&nbsp; </b></font></td> <td width=\"50%\" colspan=\"2\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>&nbsp; </b></font></td> </tr> <tr> <td width=\"50%\" colspan=\"2\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>&nbsp; </b></font></td> <td width=\"50%\" colspan=\"2\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>&nbsp; </b></font></td> </tr> <tr> <td width=\"50%\" colspan=\"2\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>PORBANDAR - 360575 </b></font></td> <td width=\"50%\" colspan=\"2\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>PORBANDAR - 360575 </b></font></td> </tr> <tr> <td width=\"50%\" colspan=\"2\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>INDIA </b></font></td> <td width=\"50%\" colspan=\"2\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>INDIA </b></font></td> </tr> <tr> <td width=\"14%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Tel. No.</b></font></td> <td width=\"36%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>0286-2243863 </b></font></td> <td width=\"14%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Tel. No.</b></font></td> <td width=\"34%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>0286 2245641 </b></font></td> </tr> <tr> <td width=\"14%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Fax. No.</b></font></td> <td width=\"36%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>&nbsp; </b></font></td> <td width=\"14%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Fax. No.</b></font></td> <td width=\"34%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>&nbsp; </b></font></td> </tr> <tr> <td width=\"14%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Mob. No.</b></font></td> <td width=\"36%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>09409059418 </b></font></td> <td width=\"14%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>Mob. No.</b></font></td> <td width=\"34%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>09409059418 </b></font></td> </tr> <tr> <td width=\"14%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>E-mail.</b></font></td> <td width=\"36%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>usthakrar@gmail.com </b></font></td> <td width=\"14%\" bgcolor=\"#CCCCFF\"><font size=\"2\"><b>E-mail.</b></font></td> <td width=\"34%\" bgcolor=\"#99CCFF\"><font size=\"2\"><b>usthakrar@gmail.com </b></font></td> </tr> </table> </div> <hr> <div align=\"right\"> <table border=\"0\" width=\"100%\"> <tr> <td width=\"29%\"> <a href=\"locm_res.asp?MRH_MRN=140337\" onclick=\"NewWindow(this.href,'mywin','500','400','no','center');return false\" onfocus=\"this.blur()\"><b><font color=\"#0000FF\">Member Employment Details</font></b></a></td> <td width=\"27%\"> <a href=\"locm_ocp.asp?MRH_MRN=140337\" onclick=\"NewWindow(this.href,'mywin','900','400','no','center');return false\" onfocus=\"this.blur()\"> <b><font color=\"#0000FF\">Member Firm Association Details</font></b></a></td> <td width=\"44%\"><b><a href=\"locm_article.asp?MRH_MRN=140337\" onclick=\"NewWindow(this.href,'mywin','900','400','yes','center');return false\" onfocus=\"this.blur()\"> <font color=\"#0000FF\"> Article / Audit (List of Student undergoing Training with details)</font></a></b></td> </tr> <tr> <td width=\"29%\"> . </td> <td width=\"27%\"> </td> <td width=\"44%\">.</td> </tr> <tr> <td width=\"100%\" colspan=\"3\" align=\"center\"> <b><font color=\"#0000FF\"><a href=\"firm_approval.asp\" onclick=\"NewWindow(this.href,'mywin','900','400','yes','center');return false\" onfocus=\"this.blur()\"> Search Firm Registered / Approved with ICAI as on Date</a></font></b></td> </tr> </table> </div> <p> &nbsp;</p> <hr> <p>&nbsp;</p> </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/