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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/(?<=Downloads: ).*?(?=<\/p>)/m'; $str = ' <!DOCTYPE html> <html lang="en" class="shortcut"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> <meta name="description" content="Downloads public domain comics as PDFs"> <meta property="og:url" content="/shortcut/958" /> <meta property="og:type" content="website" /> <meta property="og:title" content="RoutineHub - Download Comic" /> <meta property="og:description" content="Downloads public domain comics as PDFs" /> <meta property="og:image" content="https://routinehub-assets.s3.amazonaws.com/media/shortcuts/icons/302d94a11ea64643a139bdf98ecb72d6.png" /> <meta name="twitter:card" content="summary" /> <title>RoutineHub • Download Comic</title> <link rel="apple-touch-icon-precomposed" sizes="57x57" href="https://routinehub-assets.s3.amazonaws.com/static/icon/apple-touch-icon-57x57.png" /> <link rel="apple-touch-icon-precomposed" sizes="114x114" href="https://routinehub-assets.s3.amazonaws.com/static/icon/apple-touch-icon-114x114.png" /> <link rel="apple-touch-icon-precomposed" sizes="72x72" href="https://routinehub-assets.s3.amazonaws.com/static/icon/apple-touch-icon-72x72.png" /> <link rel="apple-touch-icon-precomposed" sizes="144x144" href="https://routinehub-assets.s3.amazonaws.com/static/icon/apple-touch-icon-144x144.png" /> <link rel="apple-touch-icon-precomposed" sizes="60x60" href="https://routinehub-assets.s3.amazonaws.com/static/icon/apple-touch-icon-60x60.png" /> <link rel="apple-touch-icon-precomposed" sizes="120x120" href="https://routinehub-assets.s3.amazonaws.com/static/icon/apple-touch-icon-120x120.png" /> <link rel="apple-touch-icon-precomposed" sizes="76x76" href="https://routinehub-assets.s3.amazonaws.com/static/icon/apple-touch-icon-76x76.png" /> <link rel="apple-touch-icon-precomposed" sizes="152x152" href="https://routinehub-assets.s3.amazonaws.com/static/icon/apple-touch-icon-152x152.png" /> <link rel="icon" type="image/png" href="https://routinehub-assets.s3.amazonaws.com/static/icon/favicon-196x196.png" sizes="196x196" /> <link rel="icon" type="image/png" href="https://routinehub-assets.s3.amazonaws.com/static/icon/favicon-96x96.png" sizes="96x96" /> <link rel="icon" type="image/png" href="https://routinehub-assets.s3.amazonaws.com/static/icon/favicon-32x32.png" sizes="32x32" /> <link rel="icon" type="image/png" href="https://routinehub-assets.s3.amazonaws.com/static/icon/favicon-16x16.png" sizes="16x16" /> <link rel="icon" type="image/png" href="https://routinehub-assets.s3.amazonaws.com/static/icon/favicon-128.png" sizes="128x128" /> <meta name="application-name" content="&nbsp;"/> <meta name="msapplication-TileColor" content="#FFFFFF" /> <meta name="msapplication-TileImage" content="https://routinehub-assets.s3.amazonaws.com/static/icon/mstile-144x144.png" /> <meta name="msapplication-square70x70logo" content="https://routinehub-assets.s3.amazonaws.com/static/icon/mstile-70x70.png" /> <meta name="msapplication-square150x150logo" content="https://routinehub-assets.s3.amazonaws.com/static/icon/mstile-150x150.png" /> <meta name="msapplication-wide310x150logo" content="https://routinehub-assets.s3.amazonaws.com/static/icon/mstile-310x150.png" /> <meta name="msapplication-square310x310logo" content="https://routinehub-assets.s3.amazonaws.com/static/icon/mstile-310x310.png" /> <link rel="stylesheet" type="text/css" href="https://routinehub-assets.s3.amazonaws.com/static/main/main.14.css" /> </head> <body> <article class="message pop-up"> <div class="message-header"> <p class="message-title"></p> <button class="delete" aria-label="delete"></button> </div> <div class="message-body"></div> </article> <nav class="navbar" role="navigation" aria-label="main navigation"> <div class="container"> <div class="navbar-brand"> <a class="navbar-item" href="/"> <img src="https://routinehub-assets.s3.amazonaws.com/static/icon/favicon-32x32.png"> <p>RoutineHub<span class="beta has-text-grey">beta</span></p> </a> <p class="search-button navbar-item is-hidden-desktop"><i class="fas fa-search"></i></p> <div class="navbar-burger"> <span></span> <span></span> <span></span> </div> </div> <div class="navbar-menu"> <div class="navbar-end has-text-right"> <p class="search-button navbar-item is-hidden-touch"><i class="fas fa-search"></i></p> <a href="/faq/" class="navbar-item">About</a> <a href="/register/" class="navbar-item">Sign up</a> <a href="/login/" class="navbar-item">Log in</a> </div> </div> </div> </nav> <div class="search hide has-background-white-ter"> <div class="search-bar"> <div class="container"> <form method="get" action="/search/"> <div class="field has-addons has-addons-centered"> <div class="control is-expanded"> <input name="q" class="input" id="id_q" type="search"> </div> <div class="control"> <button type="submit" class="button is-dark"> <i class="fas fa-search"></i> </button> </div> </div> </form> </div> </div> </div> <div class="banner has-background-success has-text-centered"> <a href="/register/"> <div class="text"> <strong>RoutineHub is a growing community around Siri Shortcuts. Click here to create your account and get started!</strong> </div> </a> </div> <section id="content" class="section"> <div class="container"> <div class="shortcut-icon is-pulled-left"> <figure class="image app is-64x64"> <img src="https://routinehub-assets.s3.amazonaws.com/media/shortcuts/icons/302d94a11ea64643a139bdf98ecb72d6.png"> </figure> </div> <div class="titles"> <h3 class="title is-3">Download Comic</h3> <h4 class="subtitle is-4">Downloads public domain comics as PDFs</h4> </div> <hr> <div class="columns"> <div class="column sidebar is-2"> <div class="actions"> <a href="/download/2310" target="_blank" class="button is-dark is-fullwidth">Get Shortcut</a> </div> <br> <p class="has-text-centered"><a href="/login/" style="text-decoration: underline;">Log in</a> or <a href="/register/" style="text-decoration: underline;">sign up</a> to vote</p> <br> <p class="is-size-5"><strong>Information</strong></p> <div class="information"> <p>Author: <a href="/user/keveridge"><strong>@keveridge</strong></a> <p>Version: 1.0.0</p> <p>Updated: 11/18/18</p> <p>Downloads: 98</p> <p>Rating: 0/5 (1)</p> <p>Categories:</p> <ul class="fa-ul"> <li> <a href="/category/entertainment"> <span class="fa-li"> <i class="fas fa-film"></i> </span> Entertainment </a> </li> <li> <a href="/category/utilities"> <span class="fa-li"> <i class="fas fa-calculator"></i> </span> Utilities </a> </li> </ul> </div> <hr> <p class="is-size-5"><strong>Required Apps</strong></p> <div class="apps columns is-mobile is-multiline"> <div class="column none"><em>None</em></div> </div> </div> <div class="column details"> <div class="description"> <h4 class="title is-4">Description</h4> <div class="content"> <p>This shortcut images from public domain comics published at http://comicbookplus.com, combines them into a PDF and saves them to the Files app.</p> <p><img alt="Download Comic" src="https://i.imgur.com/dP5JXKz.gif"></p> </div> </div> <hr> <div class="latest-release"> <h4 class="title is-4">Latest Release Notes</h4> <p><strong>1.0.0 - Nov. 18, 2018, 2:45 p.m.</strong></p> <p>Initial release</p> <br> <p><em><a href="/shortcut/958/changelog">All release notes</a></em></p> </div> <hr> <div class="feedback"> <h4 class="title is-4">Feedback</h4> <p><a href="/login/" style="text-decoration: underline;">Log in</a> or <a href="/register/" style="text-decoration: underline;">sign up</a> to leave feedback.</p> <br> <p>No feedback yet</p> </div> </div> </div> </div> </section> <footer class="footer"> <div class="container"> <div class="footer-links"> <div class="columns has-text-right-desktop has-text-left-touch"> <div class="column is-6 is-hidden-mobile"> <div class="content has-text-white-ter has-text-left is-size-7"> <p>Copyright © 2018 Hardly Software LLC. All rights reserved.</p> <p>We are not affiliated, associated, authorized, endorsed by, or in any way officially connected with Apple Inc., or any of its subsidiaries or its affiliates. The official Apple website can be found at <a href="https://www.apple.com/" class="has-text-white-ter">https://www.apple.com/</a>. The name “Apple” as well as related names, marks, emblems and images are registered trademarks of Apple Inc.</p> <p>The use in this website and/or in related promotional print or video material of trademarked names and images is strictly for editorial and descriptive purposes, and no commercial claim to their use, or suggestion of sponsorship or endorsement, is made by Hardly Software LLC. Those words or terms that the authors and publisher have reason to believe are trademarks are designated as such by the use of initial capitalization, where appropriate. However no attempt has been made to identify or designate all words or terms to which trademark or other proprietary rights may exist. Nothing contained herein is intended to express a judgment on, or affect the validity of legal status of, any word or term as a trademark, service mark, or other proprietary mark.</p> </div> </div> <div class="column is-2"> <p class="footer-link title is-size-5"> <a href="/">Home</a> </p> <p class="footer-link"> <a href="/register/">Sign up</a> </p> <p class="footer-link"> <a href="/login/">Log in</a> </p> <p class="footer-link"> <a href="/changelog/">Changelog</a> </p> <p class="footer-link"> <a href="https://stats.uptimerobot.com/5QODDT518" target="_blank">Status page</a> </p> <p class="footer-link"> <a href="/shortcuts/latest/feed/">RSS Feed</a> </p> <p class="footer-link"> <a href="/faq/">FAQ</a> </p> </div> <div class="column is-2"> <p class="footer-link title is-size-5"> <a>Links</a> </p> <p class="footer-link"> <a href="https://feedback.routinehub.co/" target="_blank">User Feedback</a> </p> <p class="footer-link"> <a href="/membership/">Community Membership</a> </p> <p class="footer-link"> <a href="https://routinehub.storenvy.com/" target="_blank">Shop</a> </p> <p class="footer-link"> <a href="https://twitter.com/routinehub" target="_blank">Twitter</a> </p> <p class="footer-link"> <a href="https://discord.gg/2xdeZxY" target="_blank">Discord (Chat)</a> </p> </div> <div class="column is-2"> <p class="footer-link title is-size-5"> <a href="/terms/">Legal</a> </p> <p class="footer-link"> <a href="/terms/">Terms of Service</a> </p> <p class="footer-link"> <a href="/privacy/">Privacy Policy</a> </p> <p class="footer-link"> <a href="/cookies/">Cookie Policy</a> </p> </div> <div class="column is-8 is-hidden-tablet"> <div class="content has-text-white-ter has-text-left is-size-7"> <p>Copyright © 2018 Hardly Software LLC. All rights reserved.</p> <p>We are not affiliated, associated, authorized, endorsed by, or in any way officially connected with Apple Inc., or any of its subsidiaries or its affiliates. The official Apple website can be found at <a href="https://www.apple.com/" class="has-text-white-ter">https://www.apple.com/</a>. The name “Apple” as well as related names, marks, emblems and images are registered trademarks of Apple Inc.</p> <p>The use in this website and/or in related promotional print or video material of trademarked names and images is strictly for editorial and descriptive purposes, and no commercial claim to their use, or suggestion of sponsorship or endorsement, is made by Hardly Software LLC. Those words or terms that the authors and publisher have reason to believe are trademarks are designated as such by the use of initial capitalization, where appropriate. However no attempt has been made to identify or designate all words or terms to which trademark or other proprietary rights may exist. Nothing contained herein is intended to express a judgment on, or affect the validity of legal status of, any word or term as a trademark, service mark, or other proprietary mark.</p> </div> </div> </div> </div> </div> </footer> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> <script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js"></script> <script src="https://routinehub-assets.s3.amazonaws.com/static/main/script.10.js"></script> </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