Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
  • 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
Processing...

Test String

Substitution
Processing...

Code Generator

Generated Code

re = /^(PageTitle = "([^"]*)")(.*)(<title>)([^<]*)(<\/title>)(.*)(<h1 id="page-title" class="font-36">)([^<]*)(<\/h1>)(.*)$/m str = '<!-- and this include too --> Must include all this too <% PageTitle = "Member Access" MetaDescription = "There are a number of degree and education paths that can lead an individual to a career in toxicology. This page is designed to provide those considering a career in toxicology with information on the profession, schooling needed, and more. The content of this page was originally developed as a printed publication called Resource Guide to Careers in Toxicology" Keywords = "SOT, Toxicology, Careers, Resource Guide" SocialImage = "http://209.183.221.233/images/sot_logo.png" SocialImageDescription = "SOT logo" SocialURL = "http://209.183.221.233/login.asp" %> <!doctype html> <html dir="ltr" lang="en"> <head> <meta charset="UTF-8"> <!-- Meta Tags --> <meta name="description" content="There are a number of degree and education paths that can lead an individual to a career in toxicology. This page is designed to provide those considering a career in toxicology with information on the profession, schooling needed, and more. The content of this page was originally developed as a printed publication called Resource Guide to Careers in Toxicology"> <meta name="keywords" content= "SOT, Toxicology, Careers, Resource Guide"> <meta name="viewport" content="width=device-width, initial-scale=1.0 shrink-to-fit=no"> <meta name="author" content="Society of Toxicology" /> <meta name ="robots" content="index" > <!-- Twitter and Facebook Social media tags --> <meta property="fb:app_id" content="309282950004135" /> <meta property="og:title" content="New Experiences in Toxicology Program" > <meta property="og:description" content="There are a number of degree and education paths that can lead an individual to a career in toxicology. This page is designed to provide those considering a career in toxicology with information on the profession, schooling needed, and more. The content of this page was originally developed as a printed publication called Resource Guide to Careers in Toxicology"> <meta property="og:image" content="http://209.183.221.233/images/sot_logo.png"> <meta property="og:url" content="http://209.183.221.233/education/st/next.asp"> <meta property="og:type" content="website" /> <!-- Non-Essential, But Recommended --> <meta property="og:site_name" content="Society of Toxicology"> <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:image:alt" content= "SOT logo"> <meta name="twitter:creator" content="@SOToxicology" /> <!-- Non-Essential, But Required for Analytics --> <meta name="twitter:site" content="@SOToxicology"> <!-- Follow Facebook\'s recommendation of a minimum dimension of 1200x630 pixels and an aspect ratio of 1.91:1, but adhere to Twitter\'s file size requirement of less than 1MB.--> <!-- Page Title --> <title>New Experiences in Toxicology Program</title> <!-- #include virtual="/_includes/header_newsite_trt.asp" --> <div id="main" class="main-content"> <section class="inner-header divider layer-overlay overlay-dark-4" data-bg-img="/images/_interior-banners/About-banner.jpg" style="background-image: url(\'/images/_interior-banners/About-banner.jpg\'); "> <div class="container pt-30 pb-30"> <!-- Section Content --> <div class="section-content"> <div class="row"> <div class="col-md-6"> <h1 id="page-title" class="font-36">New Experiences in Toxicology Program</h1> <ol class="breadcrumb text-left mt-10 white"> <li class="active">New Experiences in Toxicology Program</li> </ol> </div> </div> </div> </div> </section> <!-- #include virtual="/_includes/social-buttons.asp" --> <!-- Indvidual Page Content Below --> <!-- #include virtual="/_global/SOTLogin.asp" --> <!-- Section: Paragraph ---> <section> <div class="container "> <div class="section-content"> <CENTER> <TABLE width=500> <TR> <TD height="0" width="226"></TD> <TD width="108"></TD> </TR> <TR> <TD height="211" valign="top"> <TABLE > <TR> <TD align=center height="185"> <noscript> Javascript not enabled. <BR>Membership functions are not available. </noscript> <% If Request.Cookies("sot-session-id") <> "" Then %> <h3>You are now logged in.<br>Please wait for the page to be redirected.</h3> <meta http-equiv=\'refresh\' content=\'1;url=/\'> <% End If %> </font></TD> </TR> </TABLE> </TD> <TD height="211"></TD> </TR> </TABLE> </CENTER> </div> <!-- /columns --> </div> </section> <!-- /section Full paragraph ends--> <!-- #include virtual="/_includes/footer.asp" --> ' subst = '$1$3$4$2$6$7$8$2$10$11' result = str.gsub(re, subst) # Print the result of the substitution puts result

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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html