Regular Expressions 101

Save & Share

  • Regex Version: ver. 3
  • 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

/
/
mg

Test String

Code Generator

Generated Code

// include the latest version of the regex crate in your Cargo.toml extern crate regex; use regex::Regex; fn main() { let regex = Regex::new(r#"(?m)<span class=\"historyDash\">-<\/span>\s*((?:[^\<]|\n)*?)\s*<\/div>"#).unwrap(); let string = " <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"> <html> <head> <title>Steam Community :: TripleThreat :: Persona name history</title> <link href=\"http://steamcommunity-a.akamaihd.net/public/shared/css/motiva_sans.css?v=F3z3QpekjE2f\" rel=\"stylesheet\" type=\"text/css\" > <link href=\"http://steamcommunity-a.akamaihd.net/public/shared/css/buttons.css?v=LNGz0aQrH--g\" rel=\"stylesheet\" type=\"text/css\" > <link href=\"http://steamcommunity-a.akamaihd.net/public/shared/css/shared_global.css?v=DOYfTk4evOTc\" rel=\"stylesheet\" type=\"text/css\" > <link href=\"http://steamcommunity-a.akamaihd.net/public/css/globalv2.css?v=RLlF4NbPEL4H\" rel=\"stylesheet\" type=\"text/css\" > <link href=\"http://steamcommunity-a.akamaihd.net/public/css/skin_1/global.css?v=gY3Z5G6712K3&amp;client=0\" rel=\"stylesheet\" type=\"text/css\" > <link href=\"http://steamcommunity-a.akamaihd.net/public/css/skin_1/group_history.css?v=8TYZeQAleI4j\" rel=\"stylesheet\" type=\"text/css\" > <link href=\"http://steamcommunity-a.akamaihd.net/public/css/skin_1/header.css?v=z3WBKGTLlnCN\" rel=\"stylesheet\" type=\"text/css\" > <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-33779068-1', 'auto', { 'sampleRate': 0.4 }); ga('set', 'dimension1', false ); ga('set', 'dimension2', 'External' ); ga('set', 'dimension3', 'profiles' ); ga('set', 'dimension4', \"profiles\\/namehistory\" ); ga('send', 'pageview'); </script> <script type=\"text/javascript\" src=\"http://steamcommunity-a.akamaihd.net/public/javascript/prototype-1.7.js?v=.55t44gwuwgvw\"></script> <script type=\"text/javascript\" src=\"http://steamcommunity-a.akamaihd.net/public/javascript/scriptaculous/_combined.js?v=9XVsa_Ni33oN&amp;l=english&amp;load=effects,controls,slider,dragdrop\"></script> <script type=\"text/javascript\" src=\"http://steamcommunity-a.akamaihd.net/public/javascript/global.js?v=VblJ8Wqm5w5i&amp;l=english\"></script> <script type=\"text/javascript\" src=\"http://steamcommunity-a.akamaihd.net/public/javascript/jquery-1.11.1.min.js?v=.isFTSRckeNhC\"></script> <script type=\"text/javascript\" src=\"http://steamcommunity-a.akamaihd.net/public/shared/javascript/tooltip.js?v=._0UFXFGgvme-\"></script> <script type=\"text/javascript\" src=\"http://steamcommunity-a.akamaihd.net/public/shared/javascript/shared_global.js?v=pU8RP8XZB6Hb&amp;l=english\"></script> <script type=\"text/javascript\">$J = jQuery.noConflict(); if ( typeof JSON != 'object' || !JSON.stringify || !JSON.parse ) { document.write( \"<scr\" + \"ipt type=\\\"text\\/javascript\\\" src=\\\"http:\\/\\/steamcommunity-a.akamaihd.net\\/public\\/javascript\\/json2.js?v=pmScf4470EZP&amp;l=english\\\"><\\/script>\\n\" ); }; </script></head> <body> <center> <!-- header bar, contains info browsing user if logged in --> <div id=\"global_header\"> <div class=\"content\"> <div class=\"logo\"> <span id=\"logo_holder\"> <a href=\"http://store.steampowered.com/\"> <img src=\"http://steamcommunity-a.akamaihd.net/public/shared/images/header/globalheader_logo.png\" width=\"176\" height=\"44\"> </a> </span> <!--[if lt IE 7]> <style type=\"text/css\"> #logo_holder img { filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0); } #logo_holder { display: inline-block; width: 176px; height: 44px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://steamcommunity-a.akamaihd.net/public/images/v5/globalheader_logo.png'); } </style> <![endif]--> </div> <div class=\"supernav_container\"> <a class=\"menuitem supernav\" href=\"http://store.steampowered.com/\" data-tooltip-type=\"selector\" data-tooltip-content=\".submenu_store\"> STORE </a> <div class=\"submenu_store\" style=\"display: none;\" data-submenuid=\"store\"> <a class=\"submenuitem\" href=\"http://store.steampowered.com/\">Featured</a> <a class=\"submenuitem\" href=\"http://store.steampowered.com/explore/\">Explore</a> <a class=\"submenuitem\" href=\"http://store.steampowered.com/curators/\">Curators</a> <a class=\"submenuitem\" href=\"http://steamcommunity.com/my/wishlist/\">Wishlist</a> <a class=\"submenuitem\" href=\"http://store.steampowered.com/news/\">News</a> <a class=\"submenuitem\" href=\"http://store.steampowered.com/stats/\">Stats</a> </div> <a class=\"menuitem supernav\" style=\"display: block\" href=\"http://steamcommunity.com/\" data-tooltip-type=\"selector\" data-tooltip-content=\".submenu_community\"> COMMUNITY </a> <div class=\"submenu_community\" style=\"display: none;\" data-submenuid=\"community\"> <a class=\"submenuitem\" href=\"http://steamcommunity.com/\">Home</a> <a class=\"submenuitem\" href=\"http://steamcommunity.com/discussions/\">Discussions</a> <a class=\"submenuitem\" href=\"http://steamcommunity.com/workshop/\">Workshop</a> <a class=\"submenuitem\" href=\"http://steamcommunity.com/greenlight/\">Greenlight</a> <a class=\"submenuitem\" href=\"http://steamcommunity.com/market/\">Market</a> <a class=\"submenuitem\" href=\"http://steamcommunity.com/?subsection=broadcasts\">Broadcasts</a> </div> <a class=\"menuitem\" href=\"http://store.steampowered.com/about/\"> ABOUT </a> <a class=\"menuitem\" href=\"https://help.steampowered.com/en/\"> SUPPORT </a> </div> <script type=\"text/javascript\"> jQuery(function($) { $('.tooltip').v_tooltip(); $('#global_header .supernav').v_tooltip({'location':'bottom', 'tooltipClass': 'supernav_content', 'offsetY':-4, 'offsetX': 1, 'horizontalSnap': 4, 'tooltipParent': '#global_header .supernav_container', 'correctForScreenSize': false}); }); </script> <div id=\"global_actions\"> <div id=\"global_action_menu\"> <div class=\"header_installsteam_btn header_installsteam_btn_green\"> <div class=\"header_installsteam_btn_leftcap\"></div> <div class=\"header_installsteam_btn_rightcap\"></div> <a class=\"header_installsteam_btn_content\" href=\"http://store.steampowered.com/about/\"> Install Steam </a> </div> <a class=\"global_action_link\" href=\"https://steamcommunity.com/login/home/?goto=id%2FTripleThreat%2Fnamehistory\">login</a> &nbsp;|&nbsp; <span class=\"pulldown global_action_link\" id=\"language_pulldown\" onclick=\"ShowMenu( this, 'language_dropdown', 'right' );\">language</span> <div class=\"popup_block_new\" id=\"language_dropdown\" style=\"display: none;\"> <div class=\"popup_body popup_menu\"> <a class=\"popup_menu_item tight\" href=\"?l=bulgarian\" onclick=\"ChangeLanguage( 'bulgarian' ); return false;\">Български (Bulgarian)</a> <a class=\"popup_menu_item tight\" href=\"?l=czech\" onclick=\"ChangeLanguage( 'czech' ); return false;\">čeština (Czech)</a> <a class=\"popup_menu_item tight\" href=\"?l=danish\" onclick=\"ChangeLanguage( 'danish' ); return false;\">Dansk (Danish)</a> <a class=\"popup_menu_item tight\" href=\"?l=dutch\" onclick=\"ChangeLanguage( 'dutch' ); return false;\">Nederlands (Dutch)</a> <a class=\"popup_menu_item tight\" href=\"?l=finnish\" onclick=\"ChangeLanguage( 'finnish' ); return false;\">Suomi (Finnish)</a> <a class=\"popup_menu_item tight\" href=\"?l=french\" onclick=\"ChangeLanguage( 'french' ); return false;\">Français (French)</a> <a class=\"popup_menu_item tight\" href=\"?l=german\" onclick=\"ChangeLanguage( 'german' ); return false;\">Deutsch (German)</a> <a class=\"popup_menu_item tight\" href=\"?l=greek\" onclick=\"ChangeLanguage( 'greek' ); return false;\">Ελληνικά (Greek)</a> <a class=\"popup_menu_item tight\" href=\"?l=hungarian\" onclick=\"ChangeLanguage( 'hungarian' ); return false;\">Magyar (Hungarian)</a> <a class=\"popup_menu_item tight\" href=\"?l=italian\" onclick=\"ChangeLanguage( 'italian' ); return false;\">Italiano (Italian)</a> <a class=\"popup_menu_item tight\" href=\"?l=japanese\" onclick=\"ChangeLanguage( 'japanese' ); return false;\">日本語 (Japanese)</a> <a class=\"popup_menu_item tight\" href=\"?l=koreana\" onclick=\"ChangeLanguage( 'koreana' ); return false;\">한국어 (Korean)</a> <a class=\"popup_menu_item tight\" href=\"?l=norwegian\" onclick=\"ChangeLanguage( 'norwegian' ); return false;\">Norsk (Norwegian)</a> <a class=\"popup_menu_item tight\" href=\"?l=polish\" onclick=\"ChangeLanguage( 'polish' ); return false;\">Polski (Polish)</a> <a class=\"popup_menu_item tight\" href=\"?l=portuguese\" onclick=\"ChangeLanguage( 'portuguese' ); return false;\">Português (Portuguese)</a> <a class=\"popup_menu_item tight\" href=\"?l=brazilian\" onclick=\"ChangeLanguage( 'brazilian' ); return false;\">Português-Brasil (Portuguese-Brazil)</a> <a class=\"popup_menu_item tight\" href=\"?l=romanian\" onclick=\"ChangeLanguage( 'romanian' ); return false;\">Română (Romanian)</a> <a class=\"popup_menu_item tight\" href=\"?l=russian\" onclick=\"ChangeLanguage( 'russian' ); return false;\">Русский (Russian)</a> <a class=\"popup_menu_item tight\" href=\"?l=schinese\" onclick=\"ChangeLanguage( 'schinese' ); return false;\">简体中文 (Simplified Chinese)</a> <a class=\"popup_menu_item tight\" href=\"?l=spanish\" onclick=\"ChangeLanguage( 'spanish' ); return false;\">Español (Spanish)</a> <a class=\"popup_menu_item tight\" href=\"?l=swedish\" onclick=\"ChangeLanguage( 'swedish' ); return false;\">Svenska (Swedish)</a> <a class=\"popup_menu_item tight\" href=\"?l=tchinese\" onclick=\"ChangeLanguage( 'tchinese' ); return false;\">繁體中文 (Traditional Chinese)</a> <a class=\"popup_menu_item tight\" href=\"?l=thai\" onclick=\"ChangeLanguage( 'thai' ); return false;\">ไทย (Thai)</a> <a class=\"popup_menu_item tight\" href=\"?l=turkish\" onclick=\"ChangeLanguage( 'turkish' ); return false;\">Türkçe (Turkish)</a> <a class=\"popup_menu_item tight\" href=\"?l=ukrainian\" onclick=\"ChangeLanguage( 'ukrainian' ); return false;\">Українська (Ukrainian)</a> <a class=\"popup_menu_item tight\" href=\"http://translation.steampowered.com\" target=\"_blank\">Help us translate Steam</a> </div> </div> </div> </div> </div> </div> <div id=\"modalBG\" style=\"display: none\"></div><script type=\"text/javascript\"> g_sessionID = \"64b42b79f53030fe530e09fa\"; g_steamID = false; // We always want to have the timezone cookie set for PHP to use setTimezoneCookies(); $J( function() { InitMiniprofileHovers(); InitEmoticonHovers(); window.BindCommunityTooltip = function( $Selector ) { $Selector.v_tooltip( {'tooltipClass': 'community_tooltip', 'dataName': 'communityTooltip' } ); }; BindCommunityTooltip( $J('[data-community-tooltip]') ); }); $J( function() { InitEconomyHovers( \"http:\\/\\/steamcommunity-a.akamaihd.net\\/public\\/css\\/skin_1\\/economy.css?v=k1KbRUnfe-Sy\", \"http:\\/\\/steamcommunity-a.akamaihd.net\\/public\\/javascript\\/economy_common.js?v=tsXdRVB0yEaR&l=english\", \"http:\\/\\/steamcommunity-a.akamaihd.net\\/public\\/javascript\\/economy.js?v=KgoJ8nBUSyBe&l=english\" );});</script><!-- /header bar --> <div id=\"mainBody\"> <!-- main contents --> <div id=\"mainContents\"> <!-- top content --> <div id=\"topGroupAvatar\"> <div class=\"mediumHolder_default\"><div class=\"avatarMedium\"><a href=\"http://steamcommunity.com/id/TripleThreat\"><img src=\"http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/80/809c91ef963bce53195c205066f91babc729e647_medium.jpg\" /></a></div></div> </div> <h2>Persona name history</h2> <h1><a id=\"topNameLink\" href=\"http://steamcommunity.com/id/TripleThreat\">TripleThreat</a></h1> <!-- /top content --> <!-- main body --> <br /> <div class=\"historyItem\"> <div class=\"historyIcon\"><img src=\"http://steamcommunity-a.akamaihd.net/public/images/skin_1/HistoryNameChange.gif\" width=\"13\" height=\"12\" border=\"0\" /></div> <span class=\"historyShort\">Name Changed</span> <span class=\"historyDash\">-</span> <span class=\"historyDate\">Jul 23 @ 12:15pm</span> <span class=\"historyDash\">-</span> TripleThreat </div> <div class=\"historyItemb\"> <div class=\"historyIcon\"><img src=\"http://steamcommunity-a.akamaihd.net/public/images/skin_1/HistoryNameChange.gif\" width=\"13\" height=\"12\" border=\"0\" /></div> <span class=\"historyShort\">Name Changed</span> <span class=\"historyDash\">-</span> <span class=\"historyDate\">Jul 23 @ 9:21am</span> <span class=\"historyDash\">-</span> [FD] TripleThreat.blyat </div> <div class=\"historyItem\"> <div class=\"historyIcon\"><img src=\"http://steamcommunity-a.akamaihd.net/public/images/skin_1/HistoryNameChange.gif\" width=\"13\" height=\"12\" border=\"0\" /></div> <span class=\"historyShort\">Name Changed</span> <span class=\"historyDash\">-</span> <span class=\"historyDate\">Jul 23 @ 8:45am</span> <span class=\"historyDash\">-</span> 9 </div> <div class=\"historyItemb\"> <div class=\"historyIcon\"><img src=\"http://steamcommunity-a.akamaihd.net/public/images/skin_1/HistoryNameChange.gif\" width=\"13\" height=\"12\" border=\"0\" /></div> <span class=\"historyShort\">Name Changed</span> <span class=\"historyDash\">-</span> <span class=\"historyDate\">Jul 23 @ 8:45am</span> <span class=\"historyDash\">-</span> 7 </div> <div class=\"historyItem\"> <div class=\"historyIcon\"><img src=\"http://steamcommunity-a.akamaihd.net/public/images/skin_1/HistoryNameChange.gif\" width=\"13\" height=\"12\" border=\"0\" /></div> <span class=\"historyShort\">Name Changed</span> <span class=\"historyDash\">-</span> <span class=\"historyDate\">Jul 23 @ 8:45am</span> <span class=\"historyDash\">-</span> 5 </div> <div class=\"historyItemb\"> <div class=\"historyIcon\"><img src=\"http://steamcommunity-a.akamaihd.net/public/images/skin_1/HistoryNameChange.gif\" width=\"13\" height=\"12\" border=\"0\" /></div> <span class=\"historyShort\">Name Changed</span> <span class=\"historyDash\">-</span> <span class=\"historyDate\">Jul 23 @ 8:45am</span> <span class=\"historyDash\">-</span> 3 </div> <div class=\"historyItem\"> <div class=\"historyIcon\"><img src=\"http://steamcommunity-a.akamaihd.net/public/images/skin_1/HistoryNameChange.gif\" width=\"13\" height=\"12\" border=\"0\" /></div> <span class=\"historyShort\">Name Changed</span> <span class=\"historyDash\">-</span> <span class=\"historyDate\">Jul 23 @ 8:45am</span> <span class=\"historyDash\">-</span> 1 </div> <div class=\"historyItemb\"> <div class=\"historyIcon\"><img src=\"http://steamcommunity-a.akamaihd.net/public/images/skin_1/HistoryNameChange.gif\" width=\"13\" height=\"12\" border=\"0\" /></div> <span class=\"historyShort\">Name Changed</span> <span class=\"historyDash\">-</span> <span class=\"historyDate\">Jul 22 @ 6:10pm</span> <span class=\"historyDash\">-</span> This is a test </div> <div class=\"historyItem\"> <div class=\"historyIcon\"><img src=\"http://steamcommunity-a.akamaihd.net/public/images/skin_1/HistoryNameChange.gif\" width=\"13\" height=\"12\" border=\"0\" /></div> <span class=\"historyShort\">Name Changed</span> <span class=\"historyDash\">-</span> <span class=\"historyDate\">Jul 14 @ 5:28pm</span> <span class=\"historyDash\">-</span> [FD] TripleThreat </div> <div class=\"historyItemb\"> <div class=\"historyIcon\"><img src=\"http://steamcommunity-a.akamaihd.net/public/images/skin_1/HistoryNameChange.gif\" width=\"13\" height=\"12\" border=\"0\" /></div> <span class=\"historyShort\">Name Changed</span> <span class=\"historyDash\">-</span> <span class=\"historyDate\">Jun 30 @ 5:44pm</span> <span class=\"historyDash\">-</span> admin </div> <br clear=\"all\" /> </div> <br clear=\"all\" /> </div> <!-- footer --> <div id=\"footer_spacer\"></div> <div id=\"footer_responsive_optin_spacer\"></div> <div id=\"footer\"> <div class=\"footer_content\"> <span id=\"footerLogo\"><img src=\"http://steamcommunity-a.akamaihd.net/public/images/skin_1/footerLogo_valve.png?v=1\" width=\"96\" height=\"26\" border=\"0\" alt=\"Valve Logo\" /></span> <span id=\"footerText\"> &copy; Valve Corporation. All rights reserved. All trademarks are property of their respective owners in the US and other countries.<br/>Some geospatial data on this website is provided by <a href=\"https://steamcommunity.com/linkfilter/?url=http://www.geonames.org\" target=\"_blank\" rel=\"noreferrer\">geonames.org</a>. <br> <span class=\"valve_links\"> <a href=\"http://store.steampowered.com/privacy_agreement/\" target=\"_blank\">Privacy Policy</a> &nbsp; | &nbsp;<a href=\"http://www.valvesoftware.com/legal.htm\" target=\"_blank\">Legal</a> &nbsp;| &nbsp;<a href=\"http://store.steampowered.com/subscriber_agreement/\" target=\"_blank\">Steam Subscriber Agreement</a> </span> </span> </div> <div class=\"responsive_optin_link\"> <div class=\"btn_medium btnv6_grey_black\" onclick=\"Responsive_RequestMobileView()\"> <span>View mobile website</span> </div> </div> </div> "; // result will be an iterator over tuples containing the start and end indices for each match in the string let result = regex.captures_iter(string); for mat in result { println!("{:?}", mat); } }

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 Rust, please visit: https://docs.rs/regex/latest/regex/