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

Code Generator

Generated Code

$re = '/<div\s*class="menu-menu-1-container">(.*?)<\/div>/s'; $str = ' <!DOCTYPE html> <!--[if IE 7]> <html class="ie ie7" lang="en-US"> <![endif]--> <!--[if IE 8]> <html class="ie ie8" lang="en-US"> <![endif]--> <!--[if !(IE 7) & !(IE 8)]><!--> <html lang="en-US"> <!--<![endif]--> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width"> <title>test</title> <link rel="profile" href="http://gmpg.org/xfn/11"> <link rel="pingback" href="http://localhost/wp/xmlrpc.php"> <!--[if lt IE 9]> <script src="http://localhost/wp/wp-content/themes/twentythirteen/js/html5.js"></script> <![endif]--> <link rel="alternate" type="application/rss+xml" title="test &raquo; Feed" href="http://localhost/wp/feed/" /> <link rel="alternate" type="application/rss+xml" title="test &raquo; Comments Feed" href="http://localhost/wp/comments/feed/" /> <script type="text/javascript"> window._wpemojiSettings = {"baseUrl":"http:\\/\\/s.w.org\\/images\\/core\\/emoji \\/72x72\\/","ext":".png","source":{"concatemoji":"http:\\/\\/localhost\\/wp\\/wp-includes\\/js\\/wp-emoji- release.min.js?ver=4.3.1"}}; !function(a,b,c){function d(a){var c=b.createElement ("canvas"),d=c.getContext&&c.getContext("2d");return d&&d.fillText?(d.textBaseline="top",d.font="600 32px Arial","flag"===a?(d.fillText(String.fromCharCode(55356,56812,55356,56807),0,0),c.toDataURL ().length>3e3):(d.fillText(String.fromCharCode(55357,56835),0,0),0!==d.getImageData(16,16,1,1).data [0])):!1}function e(a){var c=b.createElement ("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g;c.supports={simple:d("simple"),flag:d("flag")},c.DOMReady=!1,c.readyCallback=function() {c.DOMReady=!0},c.supports.simple&&c.supports.flag||(g=function(){c.readyCallback ()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)): (a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function() {"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e (f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))} (window,document,window._wpemojiSettings); </script> <style type="text/css"> img.wp-smiley, img.emoji { display: inline !important; border: none !important; box-shadow: none !important; height: 1em !important; width: 1em !important; margin: 0 .07em !important; vertical-align: -0.1em !important; background: none !important; padding: 0 !important; } </style> <link rel=\'stylesheet\' id=\'twentythirteen-fonts-css\' href=\'https://fonts.googleapis.com/css? family=Source+Sans+Pro%3A300%2C400%2C700%2C300italic%2C400italic%2C700italic%7CBitter %3A400%2C700&#038;subset=latin%2Clatin-ext\' type=\'text/css\' media=\'all\' /> <link rel=\'stylesheet\' id=\'genericons-css\' href=\'http://localhost/wp/wp- content/themes/twentythirteen/genericons/genericons.css?ver=3.03\' type=\'text/css\' media=\'all\' /> <link rel=\'stylesheet\' id=\'twentythirteen-style-css\' href=\'http://localhost/wp/wp- content/themes/twentythirteen/style.css?ver=2013-07-18\' type=\'text/css\' media=\'all\' /> <!--[if lt IE 9]> <link rel=\'stylesheet\' id=\'twentythirteen-ie-css\' href=\'http://localhost/wp/wp- content/themes/twentythirteen/css/ie.css?ver=2013-07-18\' type=\'text/css\' media=\'all\' /> <![endif]--> <script type=\'text/javascript\' src=\'http://localhost/wp/wp-includes/js/jquery/jquery.js? ver=1.11.3\'></script> <script type=\'text/javascript\' src=\'http://localhost/wp/wp-includes/js/jquery/jquery-migrate.min.js? ver=1.2.1\'></script> <link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://localhost/wp/xmlrpc.php?rsd" /> <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://localhost/wp/wp- includes/wlwmanifest.xml" /> <meta name="generator" content="WordPress 4.3.1" /> <style type="text/css">.recentcomments a{display:inline !important;padding:0 ! important;margin:0 !important;}</style> <style type="text/css" id="twentythirteen-header-css"> .site-header { background: url(http://localhost/wp/wp- content/themes/twentythirteen/images/headers/circle.png) no-repeat scroll top; background-size: 1600px auto; } @media (max-width: 767px) { .site-header { background-size: 768px auto; } } @media (max-width: 359px) { .site-header { background-size: 360px auto; } } </style> </head> <body class="single-author"> <div id="page" class="hfeed site"> <header id="masthead" class="site-header" role="banner"> <a class="home-link" href="http://localhost/wp/" title="test" rel="home"> <h1 class="site-title">test</h1> <h2 class="site-description">Just another WordPress site</h2> </a> <div id="navbar" class="navbar"> <nav id="site-navigation" class="navigation main-navigation" role="navigation"> <button class="menu-toggle">Menu</button> <a class="screen-reader-text skip-link" href="#content" title="Skip to content">Skip to content</a> <div class="menu-menu-1-container"><ul id="primary-menu" class="nav-menu"><li id="menu-item-35" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-35"><a href="http://gooogle.com">chekc</a></li> <li id="menu-item-32" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has- children menu-item-32"><a href="http://localhost/wp/sample-page/">Sample Page</a> <ul class="sub-menu"> <li id="menu-item-33" class="menu-item menu-item-type-post_type menu-item-object-post menu- item-has-children menu-item-33"><a href="http://localhost/wp/2015/09/21/hello-world/">test heloo</a> <ul class="sub-menu"> <li id="menu-item-34" class="menu-item menu-item-type-post_type menu-item-object-post menu-item-34"><a href="http://localhost/wp/2015/09/24/testkj/">testkj</a></li> </ul> </li> </ul> </li> <li id="menu-item-39" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item- 39"><a href="http://localhost/wp/category/uncategorized/">Uncategorized</a></li> <li id="menu-item-40" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item- 40"><a href="http://localhost/wp/category/test/">testttt</a></li> </ul></div> <form role="search" method="get" class="search-form" action="http://localhost/wp/"> <label> <span class="screen-reader-text">Search for:</span> <input type="search" class="search-field" placeholder="Search &hellip;" value="" name="s" title="Search for:" /> </label> <input type="submit" class="search-submit" value="Search" /> </form> </nav><!-- #site-navigation --> </div><!-- #navbar --> </header><!-- #masthead --> <div id="main" class="site-main"> '; preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 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