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

/
/
g

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"container-middle").unwrap(); let string = " <!-- start main content --> <div class=\"container-middle\"> <!-- start Firm about section --> <section class=\"row content profile-about fp-about\"> <!-- start article --> <article class=\"large-8 medium-12 columns\"> <!-- start main content --> <a name=\"fp-about\"></a> <h2>About McCrory Law Firm</h2> <div class=\"firm-profile-logo \"> <img src=\"https://images.lawyers.com/LBM_Images/Offices/law-firm-mccrory-law-firm-photo-5044786.png\" alt=\"McCrory Law Firm\" title=\"McCrory Law Firm (punta-gorda, Florida)\"> </div> <div class=\"show-less-content logo-video \"> The firm as a whole strives to be a pillar of the community, providing professional legal services with a personal and friendly philosophy.<br><br>Attorney A. Jill C. McCrory founded the McCrory Law Firm on the basis of honesty, integrity and the desire to assist people in their estate planning, business planning, and real estate legal needs. Our attorneys have the ability to think critically to craft solutions tailored to the client's needs.T... <p><a class=\"read-more read-more-content\" href=\"#\">Read more</a></p> </div> <div class=\"show-more-content\"> The firm as a whole strives to be a pillar of the community, providing professional legal services with a personal and friendly philosophy.<br><br>Attorney A. Jill C. McCrory founded the McCrory Law Firm on the basis of honesty, integrity and the desire to assist people in their estate planning, business planning, and real estate legal needs. Our attorneys have the ability to think critically to craft solutions tailored to the client's needs.The McCrory Team has the skills, knowledge, and dedication to promote client confidence and satisfaction. The firm as a whole strives to be a pillar of the community, providing professional legal services with a personal and friendly philosophy.The McCrory Law Firm is conveniently located in downtown Punta Gorda, with ample parking.Areas of Practice:Wills, Trusts & Estate PlanningProbate & Trust AdministrationBusiness LawTax LawMarital & Family LawCivil Litigation & MediationReal Estate & Title InsuranceZoning & Land Use Law <p><a class=\"read-more read-less-content smooth-scrolling\" href=\"#fp-about\">Read less</a></p> </div> <!-- end main content --> <!-- start main content --> <div class=\"container-middle\"> <!-- start Firm Area of Law section --> <section class=\"row content profile-area-of-law fp-area-of-law\"> <!-- start article --> <article class=\"large-8 medium-12 columns\"> <!-- start main content --> <a name=\"profile-aops\"></a> <h3>Areas of Law</h3> <div class=\"profile-aops-area see-more-aop-mobile \"> <ul> <li><span>General Practice</span></li> </ul> </div> <!-- end main content --> <!-- start main content --> <div class=\"container-middle\"> <!-- start Firm about section --> <section class=\"row content profile-about fp-about\"> <!-- start article --> <article class=\"large-8 medium-12 columns\"> <!-- start main content --> <a name=\"fp-about\"></a> <h2>About Shelley Guy Reynolds Attorney at Law</h2> <div class=\"firm-profile-logo \"> <img src=\"https://images.lawyers.com/LBM_Images/Offices/law-firm-law-office-of-shelley-guy-reynolds-pa-photo-5059440.png\" alt=\"Shelley Guy Reynolds Attorney at Law\" title=\"Shelley Guy Reynolds Attorney at Law (pensacola, Florida)\"> </div> <div class=\"show-less-content logo-video \"> When faced with criminal charges, losing your freedom, possessions, government pensions and civil rights where the stakes can be very high you want a criminal defense attorney on your side who is smart, aggressive and cares about your case.<br><br>Criminal defense attorney, Shelley Guy Reynolds, is dedicated to the practice of Adult and Juvenile Criminal Law and domestic violence matters. Criminal law cases are our only focus. It is our criminal... <p><a class=\"read-more read-more-content\" href=\"#\">Read more</a></p> </div> <div class=\"show-more-content\"> When faced with criminal charges, losing your freedom, possessions, government pensions and civil rights where the stakes can be very high you want a criminal defense attorney on your side who is smart, aggressive and cares about your case.<br><br>Criminal defense attorney, Shelley Guy Reynolds, is dedicated to the practice of Adult and Juvenile Criminal Law and domestic violence matters. Criminal law cases are our only focus. It is our criminal defense focus that allows our office to put all of our attention into new developments in criminal defense strategy, changes in the law, case law and investigative techniques to help in your legal defense. Our office handles all criminal law matters in County, Circuit and Federal Courts in northwest Florida. When your freedom and life is at stake, you do not need a jack of all trades, you need a master of one and one dedicated to defending you. Located in downtown Pensacola, our office represents clients facing criminal law matters in Pensacola, Milton, Pace, Gulf Breeze, Navarre as well as all of Escambia, Santa Rosa, Okaloosa, Walton, and Washington Counties in Florida. Mrs. Reynolds, is a former state prosecutor and is the only practicing criminal lawyer in the area who is a former juvenile prosecutor. Mrs. Reynolds', a Martindale-Hubbell BV Distinguished rated attorney, has the experience as a prosecution and defense attorney. This experience, provides Mrs. Reynolds with a unique perspective into your case which is helpful in researching, planning and executing the best legal strategy for your case. Mrs. Reynolds has built her criminal defense practice around the philosophy that every client is important and that our client’s legal matters are serious to us. Shelley Guy Reynolds Attorney at Law will return all calls and emails promptly. If we are hired to represent you, our office will work very hard to defend your rights. So if you are charged with a crime our office will treat you with the respect and dignity you deserve. When faced with criminal charges, losing your freedom, possessions, government pensions and civil rights where the stakes can be very high you want a criminal defense attorney on your side who is smart, aggressive and cares about your case protecting your rights. It is important to remember, your rights need to be protected all the way through sentencing to ensure that your sentence is fair and if possible work out the best possible deal. You want an attorney dedicated to the practice of criminal law who has the experience, knowledge, connections, determination and an excellent work ethic working for you. If you are currently investigated by law enforcement, time is very important. There is a very narrow window of time in which your attorney can work with law enforcement and the state attorney's office in your behalf possibly reducing or avoiding criminal charges all together. Furthermore, you never want to give any statements without your attorney present under any circumstances. It is ok to cooperate, however, only under the supervision and protection of your attorney. Some of the types of cases we have handed include, but not limited to, DUI, Computer Crimes, Child Pornography, Sexual Battery, Bank Robbery, Drug Offenses, Cocaine Trafficking and possession, Marijuana Trafficking and possession, Fraud, Falsifying Official Records, Theft, Grand Theft Auto, Weapons Charges, Shootings, Domestic Violence, Violation of Probation, Unlicensed Contractors, Bomb Threats, Burglary, Leaving the Scene of an Accident, Boating Under the Influence, ATF Charges, Drinking Under Age, Meth Cases and manufacturing, Grow House Operations, Bank Fraud, Mail Fraud, Sexual Assault, Lewd Or Lascivious Acts With Child, Resisting Arrest, Violation of Domestic Violence Injunctions, Armed Robbery, Forgery, Worthless Checks, Computer Hacking, Assault with a deadly weapon and more. Please take your time to read through our web site to learn more about our office, it’s staff, and our qualifications. Our web site offers a lot of useful information to help guide you through the process. If you have questions or would like to set up a consultation with Mrs. Shelley Guy Reynolds, please feel free to call our office at (850) 434 1330 or email us at info@shelleyreynolds.com. We will promptly answer all your questions. <p><a class=\"read-more read-less-content smooth-scrolling\" href=\"#fp-about\">Read less</a></p> </div> <!-- end main content --> <!-- start main content --> <div class=\"container-middle\"> <!-- start Firm about section --> <section class=\"row content profile-about fp-about\"> <!-- start article --> <article class=\"large-8 medium-12 columns\"> <!-- start main content --> <a name=\"fp-about\"></a> <h2>About Law Offices of Alex Hanna</h2> <div class=\"firm-profile-logo \"> <img src=\"https://images.lawyers.com/LBM_Images/Offices/law-firm-law-offices-of-alex-hanna-photo-5040059.png\" alt=\"Law Offices of Alex Hanna\" title=\"Law Offices of Alex Hanna (miami, Florida)\"> </div> <div class=\"show-less-content logo-video \"> Experienced Attorneys defending against DUI’s, Traffic Violations Criminal Cases and representing Accident Victims. Call Alex Hanna Today!<br><br><p>Available day or night, 24 hours a day, 7 days a week.</p><p>Injured in an auto accident? Slip-and-fall? or other Personal Injury? We can also help you seek compensation to pay for medical bills, lost wages, and pain and suffering. Call Alex Hanna Now! There is no fee nor costs if there is no recover... <p><a class=\"read-more read-more-content\" href=\"#\">Read more</a></p> </div> <div class=\"show-more-content\"> Experienced Attorneys defending against DUI’s, Traffic Violations Criminal Cases and representing Accident Victims. Call Alex Hanna Today!<br><br><p>Available day or night, 24 hours a day, 7 days a week.</p><p>Injured in an auto accident? Slip-and-fall? or other Personal Injury? We can also help you seek compensation to pay for medical bills, lost wages, and pain and suffering. Call Alex Hanna Now! There is no fee nor costs if there is no recovery in accident cases.</p><p>Attorney Alex Hanna and his Team of Attorneys offer a full range of legal services. If you are facing a DUI, ticket, criminal or accident, don't risk losing your license, paying huge fines or serving jail time. Contact our office. If you have been injured, you could receive compensation for your injuries.</p><p></p><p>Every case is unique. Attorney Alex Hanna and his Team of Attorneys will explore all defenses and other possible legal avenues to Fight for Your Rights! Traffic Tickets?: You may be able to avoid: points, traffic school, and/or court appearances (applicable only in noncriminal).</p> <p><a class=\"read-more read-less-content smooth-scrolling\" href=\"#fp-about\">Read less</a></p> </div> <!-- end main content --> </article> <!-- start main content --> <div class=\"container-middle\"> <!-- start Firm about section --> <section class=\"row content profile-about fp-about\"> <!-- start article --> <article class=\"large-8 medium-12 columns\"> <!-- start main content --> <a name=\"fp-about\"></a> <h2>About The Charles Law Offices</h2> <div class=\"show-less-content \"> Vigilant. Respectful. Effective. An accomplished attorney providing Tampa Bay area residents with counsel in estate planning, probate and trust administration, Medicaid planning, Veterans Aid, and other elder-related matters. Call us today<br><br>Dealing with estate planning and probate issues can be challenging. Whether you are just beginning to contemplate what your estate planning goals are or you have just discovered that a loved one has passed away and that it was his or her intention that you be the one to handle his or her affairs, having a knowledgeable, capable guide there to help you sort through all of the details can help you have peace of mind. <p>At The Charles Law Offices, our Clearwater elder la... <p><a class=\"read-more read-more-content\" href=\"#\">Read more</a></p> </div> <div class=\"show-more-content\"> Vigilant. Respectful. Effective. An accomplished attorney providing Tampa Bay area residents with counsel in estate planning, probate and trust administration, Medicaid planning, Veterans Aid, and other elder-related matters. Call us today<br><br>Dealing with estate planning and probate issues can be challenging. Whether you are just beginning to contemplate what your estate planning goals are or you have just discovered that a loved one has passed away and that it was his or her intention that you be the one to handle his or her affairs, having a knowledgeable, capable guide there to help you sort through all of the details can help you have peace of mind. <p>At The Charles Law Offices, our Clearwater elder law attorney brings together a deep understanding of the laws that apply to estate planning. From tax issues to qualifying for government benefits, we are able to construct estate plans that balance all of the necessities of estate planning to allow your intentions to be honored. <p>It is difficult enough to begin thinking about the planning of your estate. The future always seems so far away. Taking steps today to arrange for your estate to be dealt with in an orderly fashion will allow you to create a plan that will minimize the burden for your loved ones and can help to ensure that the portion of the estate that gets lost to taxes is as small as possible. <p>Attorney Susan Charles is committed to providing exceptional estate planning service to our clients. Attorney Charles holds a Master of Laws (LL.M., an advanced legal degree) in Elder Law in addition to her Juris Doctor (J.D.). <p>For effective estate planning guidance and probate, estate and trust administration, turn to The Charles Law Offices. We take pride in the level of support we provide to our clients. <p><a class=\"read-more read-less-content smooth-scrolling\" href=\"#fp-about\">Read less</a></p> </div> <!-- end main content --> <!-- start main content --> <div class=\"container-middle\"> <!-- start Firm Area of Law section --> <section class=\"row content profile-area-of-law fp-area-of-law\"> <!-- start article --> <article class=\"large-8 medium-12 columns\"> <!-- start main content --> <a name=\"profile-aops\"></a> <h3>Areas of Law</h3> <div class=\"profile-aops-area see-more-aop-mobile column-aop-3\"> <ul> <li><span>Animal Law</span></li> <li><span>Criminal Law</span></li> <li><span>Family Law</span></li> <li><span>Trial Lawyers</span></li> </ul> </div> <!-- end main content --> <!-- start main content --> <div class=\"container-middle\"> <!-- start Firm about section --> <section class=\"row content profile-about fp-about\"> <!-- start article --> <article class=\"large-8 medium-12 columns\"> <!-- start main content --> <a name=\"fp-about\"></a> <h2>About Mateer &amp; Harbert, P.A.</h2> <div class=\"firm-profile-logo \"> <img src=\"https://images.lawyers.com/LBM_Images/Offices/law-firm-mateer-harbert-pa-photo-3460791.jpeg\" alt=\"Mateer &amp; Harbert, P.A.\" title=\"Mateer &amp; Harbert, P.A. (ocala, Florida)\"> </div> <br><br> <!-- end main content --> <!-- start main content --> <div class=\"container-middle\"> <!-- start Firm about section --> <section class=\"row content profile-about fp-about\"> <!-- start article --> <article class=\"large-8 medium-12 columns\"> <!-- start main content --> <a name=\"fp-about\"></a> <h2>About MacLeod, McGinness &amp; Bowman, P.A.</h2> <div class=\"firm-profile-logo \"> <img src=\"https://images.lawyers.com/LBM_Images/Offices/law-firm-macleod-mcginness-bowman-pa-photo-1630017.png\" alt=\"MacLeod, McGinness &amp; Bowman, P.A.\" title=\"MacLeod, McGinness &amp; Bowman, P.A. (st.-petersburg, Florida)\"> </div> <div class=\"show-less-content\"> Clients include individuals seeking counsel in estate planning and estate and trust administration and business transactions. </div> <!-- end main content --> <!-- start main content --> <div class=\"container-middle\"> <!-- start Firm about section --> <section class=\"row content profile-about fp-about\"> <!-- start article --> <article class=\"large-8 medium-12 columns\"> <!-- start main content --> <a name=\"fp-about\"></a> <h2>About Sweetwater Law Offices, PLC</h2> <div class=\"show-less-content\"> Counselor and Attorney at Law<br><br> </div> <!-- end main content --> <!-- start main content --> <div class=\"container-middle\"> <!-- start Firm about section --> <section class=\"row content profile-about fp-about\"> <!-- start article --> <article class=\"large-8 medium-12 columns\"> <!-- start main content --> <a name=\"fp-about\"></a> <h2>About Smith, Currie &amp; Hancock LLP</h2> <div class=\"show-less-content\"> The firm was established in 1965 and is one of the largest law firms in the United States concentrating in Construction Law and Government Contracts, as well as handling Commercial matters, Litigation, Arbitration and Mediation. Clients include multinational and Fortune 500 Companies and Trade Associations. </div> <!-- end main content --> "; // result will be an iterator over tuples containing the start and end indices for each match in the string let result = regex.captures_iter(string); for mat in result { println!("{:?}", mat); } }

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/