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

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"(?s)(<pre>.+?<\/pre>)" test_str = (" <!DOCTYPE HTML>\n" "<html lang=\"en-US\">\n" "<head>\n\n" " <meta charset=\"UTF-8\">\n" " <title>'HPTjNRgUfG' | TextUploader.com</title>\n" " <meta name=\"viewport\" content=\"initial-scale=1.0,maximum-scale=1.0,user-scalable=no\">\n" " <link rel=\"icon\" type=\"image/ico\" href=\"http://textuploader.com/favicon.ico\">\n\n" " <meta property=\"og:title\" content=\"HPTjNRgUfG\" xmlns=\"http://www.w3.org/1999/html\"/>\n" " <meta property=\"og:type\" content=\"article\"/>\n" " <meta property=\"og:url\" content=\"http://textuploader.com/5jx4u\"/>\n" " <meta property=\"og:site_name\" content=\"textuploader.com - HPTjNRgUfG\"/>\n" " <meta property=\"og:description\" content=\"Please call back later &lt;a href=&quot; http://philadelphiaexplorers.org/about-the-explorers-club/#annual &quot;&gt;a...\"/>\n" " <link rel=\"canonical\" href=\"http://textuploader.com/5jx4u\"/>\n" " <!-- bootstrap framework css -->\n" " <link media=\"all\" type=\"text/css\" rel=\"stylesheet\" href=\"//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.0/css/bootstrap.min.css\">\n" " <link media=\"all\" type=\"text/css\" rel=\"stylesheet\" href=\"//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.0/css/bootstrap-responsive.min.css\">\n" " <!-- power tooltips -->\n" " <link media=\"all\" type=\"text/css\" rel=\"stylesheet\" href=\"//cdnjs.cloudflare.com/ajax/libs/jquery-powertip/1.1.0/jquery.powertip.css\">\n\n" " <!-- main stylesheet -->\n" " <link media=\"all\" type=\"text/css\" rel=\"stylesheet\" href=\"http://textuploader.com/assets/css/beoro.css\">\n" " <link media=\"all\" type=\"text/css\" rel=\"stylesheet\" href=\"http://textuploader.com/assets/css/tu_custom.css\">\n\n" " <!--[if lte IE 8]><link media=\"all\" type=\"text/css\" rel=\"stylesheet\" href=\"http://textuploader.com/assets/css/ie8.css\">\n" "<![endif]-->\n" " <!--[if IE 9]><link media=\"all\" type=\"text/css\" rel=\"stylesheet\" href=\"http://textuploader.com/assets/css/ie9.css\">\n" "<![endif]-->\n\n" " <!--[if lt IE 9]>\n" " <script src=\"//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.2pre/html5shiv.js\"></script>\n" " <script src=\"//cdnjs.cloudflare.com/ajax/libs/respond.js/1.1.0/respond.min.js\"></script>\n" " <script src=\"//cdnjs.cloudflare.com/ajax/libs/flot/0.7/excanvas.min.js\"></script>\n" " <![endif]-->\n\n" " <script type=\"text/javascript\">\n" " var _gaq = _gaq || [];\n" " _gaq.push(['_setAccount', 'UA-36314765-1']);\n" " _gaq.push(['_setDomainName', 'textuploader.com']);\n" " _gaq.push(['_setAllowLinker', true]);\n" " _gaq.push(['_trackPageview']);\n" " (function() {\n" " var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n" " ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n" " var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n" " })();\n" " </script>\n\n\n\n" " <link media=\"all\" type=\"text/css\" rel=\"stylesheet\" href=\"//cdnjs.cloudflare.com/ajax/libs/highlight.js/7.3/styles/default.min.css\">\n" " <script src=\"//cdnjs.cloudflare.com/ajax/libs/highlight.js/7.3/highlight.min.js\"></script>\n" " <script>hljs.initHighlightingOnLoad();</script>\n\n" "</head>\n\n" "<body class=\"bg_c\">\n\n" "<div id=\"fb-root\"></div>\n" "<script>(function (d, s, id) {\n" " var js, fjs = d.getElementsByTagName(s)[0];\n" " if (d.getElementById(id)) return;\n" " js = d.createElement(s);\n" " js.id = id;\n" " js.src = \"//connect.facebook.net/en_US/all.js#xfbml=1&appId=456470037742170\";\n" " fjs.parentNode.insertBefore(js, fjs);\n" " }(document, 'script', 'facebook-jssdk'));</script>\n" "<!-- main wrapper (without footer) -->\n" "<div class=\"main-wrapper\">\n" " <!-- top bar -->\n\n" " <div class=\"navbar navbar-fixed-top\">\n" " <div class=\"navbar-inner\">\n" " <div class=\"container\">\n" " <div class=\"pull-right top-search\">\n" " </div>\n\n\n" " <div id=\"fade-menu\" class=\"pull-left\">\n" " <ul class=\"clearfix\" id=\"mobile-nav\">\n" " <li><a href=\"http://textuploader.com/\">Home</a></li>\n" " <li><a href=\"http://textuploader.com/discover\">Discover</a></li>\n" " <li><a href=\"http://textuploader.com/help\">Help</a></li>\n" " <li><a href=\"http://textuploader.com/developers\">Developers</a></li>\n" " <li><a href=\"http://textuploader.com/contact\">Contact</a></li>\n\n" " <li><a href='https://textuploader.com/profile'>My Account</a>\n" " </li>\n\n\n\n" " </ul>\n" " </div>\n\n" " </div>\n" " </div>\n" " </div>\n\n" " <!-- header -->\n" " <header>\n" " <div class=\"container\">\n" " <div class=\"row\">\n" " <div class=\"span3\">\n" " <!-- <div class=\"main-logo\"><a href=\"http://textuploader.com/\"><img src=\"http://textuploader.com/assets/img/textuploader_logo.png\" alt=\"TextUploader.com\"></div> -->\n" " <div class=\"main-logo\"><a href='http://textuploader.com/'><img src=\"http://textuploader.com/assets/img/textuploader_logo.png\" alt=\"TextUploader.com\"></a></div>\n" " </div>\n" " <div class=\"span5\">\n" " <nav class=\"nav-icons\">\n" " <!-- small icons navigation -->\n" " </nav>\n" " </div>\n" " <div class=\"span4\">\n" " <div class=\"user-box\">\n" " <div class=\"user-box-inner\">\n" " <img src=\"//www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?s=80&r=g&d=mm\" class=\"user-avatar img-avatar\" alt=\"Gravatar\"/>\n\n" " <div class=\"user-info\">\n" " <a href=\"https://textuploader.com/register\">Create an Account</a> <ul class=\"unstyled\">\n" " <li><a href=\"https://textuploader.com/auth/login\">Login</a></li>\n" " <li>&middot;</li>\n" " <li><a href=\"https://textuploader.com/auth/password/forgot\">Password</a></li>\n" " </ul>\n" " </div>\n" " </div>\n" " </div>\n" " </div>\n" " </div>\n" " </div>\n" " </header>\n\n" " <!-- breadcrumbs -->\n" " <div class=\"container\">\n" " <ul id=\"breadcrumbs\">\n" " <li>\n" " <a href=\"http://textuploader.com/\">\n" " <i class=\"icon-home\"></i>\n" " </a></li>\n\n" " <li><a href=\"http://textuploader.com/\">Home</a></li>\n" " <li><a href=\"http://textuploader.com/5jx4u\">textuploader.com/5jx4u</a></li>\n\n" " <li><span>Posted on: 11/16/15 1:59:00 AM UTC</span></li>\n" " </ul>\n" " </div>\n\n\n" " <!-- main content -->\n" " <div class=\"container\">\n" " <div class=\"row-fluid\">\n" " <div class=\"span12\">\n" " <div class=\"w-box w-box-blue\">\n" " <div class=\"w-box-header\"><h4>\"HPTjNRgUfG\" - Views: 2 &middot; Hits: 2 - Type: Public</h4></div>\n" " <div class=\"w-box-content cnt_a \">\n\n\n" "<div class=\"toolbar clearfix\">\n" " <div class=\"pull-left\">\n" " <div class=\"toolbar-icons clearfix\">\n" " <div style=\"overflow:hidden;width:90px;float:left;\">\n" " <div class=\"fb-like\" data-href=\"http://textuploader.com/5jx4u\" data-send=\"false\" data-layout=\"button_count\"\n" " data-width=\"450\" data-show-faces=\"false\"></div>\n" "</div>\n" "<div style=\"overflow:hidden;width:90px;float:left;\">\n" " <a href=\"https://twitter.com/share\" class=\"twitter-share-button\" data-url=\"http://textuploader.com/5jx4u\">Tweet</a>\n" "</div>\n" "<div style=\"overflow:hidden;width:90px;float:left;\">\n" " <div class=\"g-plusone\" data-size=\"medium\" data-annotation=\"none\"\n" " data-href=\"http://textuploader.com/5jx4u\"></div>\n" "</div>\n" "<div style=\"clear:both\"></div>\n\n\n" " </div>\n" " </div>\n" " <div class=\"pull-right\">\n" " <div class=\"btn-group\">\n" " <button class=\"btn btn-mini\" onClick=\"parent.location='http://textuploader.com/5jx4u/rev'; void(0);\">Revisions (0)</button>\n" " <button class=\"btn btn-mini\" onClick=\"parent.location='http://textuploader.com/contact'; void(0);\">Report Abuse</button>\n" " </div>\n" " </div>\n" "</div>\n" "<pre><code class='no-highlight'>Please call back later &lt;a href=&quot; http://philadelphiaexplorers.org/about-the-explorers-club/#annual &quot;&gt;accidently took 2 40 mg paxil&lt;/a&gt; &quot;We need that flexibility,&quot; Fox said. &quot;When you pick your offensive line, not just for the season, but for game day, you have to pick them from the standpoint of having some flexibility. You&#039;ve got to have a swing guard/center, you&#039;ve got to have a swing tackle/guard, for the games.&quot;\n" " </code></pre>\n\n\n" " </div>\n" " </div>\n" " </div>\n\n" " </div>\n\n\n" " </div>\n\n" " <div class=\"footer_space\"></div>\n" "</div>\n" "<!-- footer -->\n" "<footer>\n" " <div class=\"container\">\n" " <div class=\"row\">\n" " <div class=\"span8\">\n" " <div>&copy; 2016 <a href=\"http://www.exsom.com\" target=\"_blank\">Exsom Group, LLC</a>. All Rights Reserved.</div>\n" " </div>\n" " <div class=\"span4\">\n" " <ul class=\"unstyled\">\n" "<!-- \n" "<li><a href=\"https://tuarmor.com\">TUArmor</a></li>\n" " <li>&middot;</li>\n" "-->\n" " <li><a href=\"http://textuploader.com/terms-of-service\">Terms of Service</a></li>\n" " <li>&middot;</li>\n" " <li><a href=\"http://textuploader.com/privacy\">Privacy Policy</a></li>\n" " <li>&middot;</li>\n" " <li><a href=\"http://textuploader.com/dmca\">DMCA</a></li>\n" " <li>&middot;</li>\n" " <li><a href=\"http://status.textuploader.com/\">System Status</a></li>\n" " </ul>\n" " </div>\n" " </div>\n" " </div>\n" "</footer>\n" "<!-- Common JS -->\n" "<!-- jQuery framework -->\n" "<script src=\"//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js\"></script>\n" "<!-- bootstrap Framework plugins -->\n" "<script src=\"//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.0//js/bootstrap.min.js\"></script>\n" "<!-- top menu -->\n" "<script src=\"http://textuploader.com/assets/js/jquery.fademenu.js\"></script>\n" "<!-- top mobile menu -->\n" "<script src=\"http://textuploader.com/assets/js/selectnav.min.js\"></script>\n" "<!-- actual width/height of hidden DOM elements -->\n" "<script src=\"http://textuploader.com/assets/js/jquery.actual.min.js\"></script>\n" "<!-- jquery easing animations -->\n" "<script src=\"//cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js\"></script>\n" "<!-- power tooltips -->\n" "<script src=\"//cdnjs.cloudflare.com/ajax/libs/jquery-powertip/1.1.0/jquery.powertip-1.1.0.min.js\"></script>\n" "<!-- date library -->\n" "<script src=\"//cdnjs.cloudflare.com/ajax/libs/moment.js/1.7.2/moment.min.js\"></script>\n" "<!-- common functions -->\n" "<script src=\"http://textuploader.com/assets/js/beoro_common.js\"></script>\n\n" "<!-- twitter button code -->\n" "<script>!function (d, s, id) {\n" " var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';\n" " if (!d.getElementById(id)) {\n" " js = d.createElement(s);\n" " js.id = id;\n" " js.src = p + '://platform.twitter.com/widgets.js';\n" " fjs.parentNode.insertBefore(js, fjs);\n" " }\n" " }(document, 'script', 'twitter-wjs');</script>\n\n" "<!-- +1 code -->\n" "<script type=\"text/javascript\">\n" " (function () {\n" " var po = document.createElement('script');\n" " po.type = 'text/javascript';\n" " po.async = true;\n" " po.src = '//apis.google.com/js/plusone.js';\n" " var s = document.getElementsByTagName('script')[0];\n" " s.parentNode.insertBefore(po, s);\n" " })();\n" "</script>\n" "</body>\n" "</html>") matches = re.search(regex, test_str) if matches: print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group())) for groupNum in range(0, len(matches.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.group(groupNum))) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

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 Python, please visit: https://docs.python.org/3/library/re.html