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
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
Processing...

Test String

Code Generator

Generated Code

import re regex = re.compile(r"<script>.*?(var.*?;).*?</script>", flags=re.DOTALL) test_str = ("<script><!--\n" "var STATIC_BASE = '//cdn1.editmysite.com/';\n" "var STYLE_PREFIX = 'wsite';\n" "//-->\n" "</script>\n" "<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>\n" "<script src='//cdn2.editmysite.com/js/site/main.js?buildTime=1400799662'></script>\n" "<script>_W.relinquish && _W.relinquish()</script>\n" "<script type='text/javascript'><!--\n" "(function(jQuery){\n" "function initFlyouts(){initPublishedFlyoutMenus([{\"id\":\"408147401478827578\",\"title\":\"HOME\",\"url\":\"index.html\",\"target\":\"\"},{\"id\":\"852985120278826572\",\"title\":\"GET A DOMAIN\",\"url\":\"get-a-domain.html\",\"target\":\"\"},{\"id\":\"745935904556716097\",\"title\":\"SERVICES\",\"url\":\"services.html\",\"target\":\"\"},{\"id\":\"505441827833699923\",\"title\":\"MY ACCOUNT\",\"url\":\"my-account.html\",\"target\":\"\"},{\"id\":\"464549931862712377\",\"title\":\"ABOUT US\",\"url\":\"about-us.html\",\"target\":\"\"}],\"408147401478827578\",\"<li><a href='#'>{{title}}<\\/a><\\/li>\",'active',false)}\n" "if (jQuery) {\n" "if (jQuery.browser.msie && !window.flyoutMenusRefreshable) window.onload = initFlyouts;\n" "else jQuery(initFlyouts);\n" "}else{\n" "if (Prototype.Browser.IE) window.onload = initFlyouts;\n" "else document.observe('dom:loaded', initFlyouts);\n" "}\n" "})(window._W && _W.jQuery)\n" "//-->\n" "</script>\n" "</head>\n" "<body class=' wsite-theme-light wsite-page-index'>\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); js.id = id;\n" " js.src = \"//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=109188665774734&version=v2.0\";\n" " fjs.parentNode.insertBefore(js, fjs);\n" "}(document, 'script', 'facebook-jssdk'));</script>\n" "<div id=\"nav-fixed\">\n" " <div id=\"nav-body\">\n" " <span style=\"visibility:hidden\">Pwns.me</span> <ul class='wsite-menu-default'><li id='active'><a href='/'>HOME</a></li><li id='pg852985120278826572'><a href='/get-a-domain.html'>GET A DOMAIN</a></li><li id='pg745935904556716097'><a href='/services.html'>SERVICES</a></li><li id='pg505441827833699923'><a href='/my-account.html'>MY ACCOUNT</a></li><li id='pg464549931862712377'><a href='/about-us.html'>ABOUT US</a></li></ul>\n" " </div>\n" "</div>\n" "<div id=\"pwns-logo\">\n" "<span style=\"display:hidden;\" david=\"gay\"></span>\n" "</div>\n" "<div id=\"content-body\">\n" "<div id=\"titleImg\">\n" "<img src=\"/files/theme/middlef.png\">\n" "</div>\n" "<div id=\"que\">\n" "<ul>\n" "<li><a href=\"about-us.html\">QUE?</a> </li>\n" "<li><a href=\"get-a-domain.html\">SEEMS LEGIT</a> </li>\n" "</ul>\n" "</div>\n\n" "</div>\n\n" "<div id=\"social\">\n" "<div class=\"fb-like\" data-href=\"http://pwns.me\" data-layout=\"button\" data-action=\"like\" data-show-faces=\"false\" data-share=\"false\"></div><br><br>\n" "<a href=\"https://twitter.com/share\" class=\"twitter-share-button\" data-url=\"http://pwns.me\" data-text=\"Pwns.me - Awesome domains\" data-count=\"none\" data-hashtags=\"pwns\">Tweet</a>\n" "<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>\n" "</div>\n\n" "<div id=\"myFooter\"> Brought to you by Awesomness. </div>\n" "<div style=\"display:none;\">\n" "<div><div class='wsite-elements wsite-footer'>\n" "<div><div class=\"wsite-multicol\"><div class='wsite-multicol-table-wrap' style='margin:0 -15px'>\n" "<table class='wsite-multicol-table'>\n" "<tbody class='wsite-multicol-tbody'>\n" "<tr class='wsite-multicol-tr'>\n" "<td class='wsite-multicol-col' style='width:50%;padding:0 15px'></td>\n" "<td class='wsite-multicol-col' style='width:50%;padding:0 15px'></td>\n" "</tr>\n" "</tbody>\n" "</table>\n" "</div></div></div>\n\n" "<div class=\"weebly-footer\" style=\"text-align:right;\"><div style=\"height:10px;overflow:hidden\"></div>\n" "Proudly powered by <a href=\"http://www.weebly.com/?utm_source=internal&utm_medium=footer&utm_campaign=2\" href=\"_blank\">Weebly</a>\n" "<div style=\"height:10px;overflow:hidden\"></div></div></div>\n" "<script type='text/javascript'>\n" "<!--\n\n" "if (document.cookie.match(/(^|;)\\s*is_mobile=1/)) {\n" " var windowHref = window.location.href || '';\n" " if (windowHref.indexOf('?') > -1) {\n" " windowHref += '&';\n" " } else {\n" " windowHref += '?';\n" " }\n" " document.write(\n" " \"&nbsp;&nbsp;&nbsp;&nbsp;\" +\n" " \"<a class='wsite-view-link-mobile' href='\" + windowHref + \"view=mobile'>Mobile Site</a>\"\n" " );\n" "}\n") match = regex.search(test_str) if match: print(f"Match was found at {match.start()}-{match.end()}: {match.group()}") for group_num, group in enumerate(match.groups(), start=1): print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")

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