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
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
No Match

r"
"
s

Test String

Code Generator

Generated Code

re = /<script>.*?(var.*?;).*?<\/script>/ str = '<script><!-- var STATIC_BASE = \'//cdn1.editmysite.com/\'; var STYLE_PREFIX = \'wsite\'; //--> </script> <script src=\'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js\'></script> <script src=\'//cdn2.editmysite.com/js/site/main.js?buildTime=1400799662\'></script> <script>_W.relinquish && _W.relinquish()</script> <script type=\'text/javascript\'><!-- (function(jQuery){ 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)} if (jQuery) { if (jQuery.browser.msie && !window.flyoutMenusRefreshable) window.onload = initFlyouts; else jQuery(initFlyouts); }else{ if (Prototype.Browser.IE) window.onload = initFlyouts; else document.observe(\'dom:loaded\', initFlyouts); } })(window._W && _W.jQuery) //--> </script> </head> <body class=\' wsite-theme-light wsite-page-index\'> <div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=109188665774734&version=v2.0"; fjs.parentNode.insertBefore(js, fjs); }(document, \'script\', \'facebook-jssdk\'));</script> <div id="nav-fixed"> <div id="nav-body"> <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> </div> </div> <div id="pwns-logo"> <span style="display:hidden;" david="gay"></span> </div> <div id="content-body"> <div id="titleImg"> <img src="/files/theme/middlef.png"> </div> <div id="que"> <ul> <li><a href="about-us.html">QUE?</a> </li> <li><a href="get-a-domain.html">SEEMS LEGIT</a> </li> </ul> </div> </div> <div id="social"> <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> <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> <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> </div> <div id="myFooter"> Brought to you by Awesomness. </div> <div style="display:none;"> <div><div class=\'wsite-elements wsite-footer\'> <div><div class="wsite-multicol"><div class=\'wsite-multicol-table-wrap\' style=\'margin:0 -15px\'> <table class=\'wsite-multicol-table\'> <tbody class=\'wsite-multicol-tbody\'> <tr class=\'wsite-multicol-tr\'> <td class=\'wsite-multicol-col\' style=\'width:50%;padding:0 15px\'></td> <td class=\'wsite-multicol-col\' style=\'width:50%;padding:0 15px\'></td> </tr> </tbody> </table> </div></div></div> <div class="weebly-footer" style="text-align:right;"><div style="height:10px;overflow:hidden"></div> Proudly powered by <a href="http://www.weebly.com/?utm_source=internal&utm_medium=footer&utm_campaign=2" href="_blank">Weebly</a> <div style="height:10px;overflow:hidden"></div></div></div> <script type=\'text/javascript\'> <!-- if (document.cookie.match(/(^|;)\\s*is_mobile=1/)) { var windowHref = window.location.href || \'\'; if (windowHref.indexOf(\'?\') > -1) { windowHref += \'&\'; } else { windowHref += \'?\'; } document.write( "&nbsp;&nbsp;&nbsp;&nbsp;" + "<a class=\'wsite-view-link-mobile\' href=\'" + windowHref + "view=mobile\'>Mobile Site</a>" ); } ' # Print the match result str.match(re) do |match| puts match.to_s end

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