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"<div class=\"instant_search_title fsl fwb fcb\"><a href=\".+?\">(.*?)<" test_str = ("<i class=\"mrs friendsIcon customimg img sp_b6fmvb sx_5e511f\"><u>Friend</u></i><span class=\"uiButtonText\">Friends</span></a></div></div><div class=\"pls\"><div class=\"instant_search_title fsl fwb fcb\"><a href=\"https://www.facebook.com/adrianasdzxc\" onclick=\"if (event.button == 0) &#123; search_logged_ajax(&#123;&quot;ab&quot;:&quot;T_GS_BACKEND_ENTITY_LIMITATION&quot;,&quot;cururl&quot;:&quot;https:\\\\/\\\\/www.facebook.com\\\\/adrianasdzxc&quot;,&quot;fc&quot;:1,&quot;gc&quot;:0,&quot;id&quot;:616226XXX,&quot;init&quot;:&quot;s:unknown&quot;,&quot;is_friend&quot;:true,&quot;is_new_user&quot;:0,&quot;locale&quot;:&quot;en_US&quot;,&quot;o_type&quot;:1,&quot;original_q&quot;:&quot;adriantnt\\\\u0040yahoo.com&quot;,&quot;q&quot;:&quot;adriantnt\\\\u0040yahoo.com&quot;,&quot;rank&quot;:0,&quot;rc&quot;:0,&quot;sid&quot;:&quot;10000108681XXXX.3365508868..1&quot;,&quot;start&quot;:0,&quot;typeahead_sid&quot;:null,&quot;u&quot;:&quot;https:\\\\/\\\\/www.facebook.com\\\\/adrianasdzxc&quot;,&quot;t&quot;:&quot;c:name&quot;&#125;); &#125;\" onmouseup=\"if (event.button != 0) &#123; search_logged_ajax(&#123;&quot;ab&quot;:&quot;T_GS_BACKEND_ENTITY_LIMITATION&quot;,&quot;cururl&quot;:&quot;https:\\\\/\\\\/www.facebook.com\\\\/adrianasdzxc&quot;,&quot;fc&quot;:1,&quot;gc&quot;:0,&quot;id&quot;:616226XXX,&quot;init&quot;:&quot;s:unknown&quot;,&quot;is_friend&quot;:true,&quot;is_new_user&quot;:0,&quot;locale&quot;:&quot;en_US&quot;,&quot;o_type&quot;:1,&quot;original_q&quot;:&quot;adriantnt\\\\u0040yahoo.com&quot;,&quot;q&quot;:&quot;adriantnt\\\\u0040yahoo.com&quot;,&quot;rank&quot;:0,&quot;rc&quot;:0,&quot;sid&quot;:&quot;10000108681XXXX.3365508868..1&quot;,&quot;start&quot;:0,&quot;typeahead_sid&quot;:null,&quot;u&quot;:&quot;https:\\\\/\\\\/www.facebook.com\\\\/adrianasdzxc&quot;,&quot;t&quot;:&quot;c:name&quot;&#125;); &#125;\" data-hovercard=\"/ajax/hovercard/user.php?id=616226XXX\">Adrian asdzxc</a></div><div class=\"fsm fwn fcg\"><div class=\"fbProfileByline searchResultPersonByline\"><span class=\"fbProfileBylineFragment\"><span class=\"fbProfileBylineIconContainer\"><i class=\"mrs fbProfileBylineIcon img sp_9pvis2 sx_897cc1\"></i></span><span class=\"fbProfileBylineLabel\">Webmaster at <a href=\"true\"><a href=\"https://www.facebook.com/pages/Freelancer/640564905962853\" data-hovercard=\"/ajax/hovercard/page.php?id=640564905962853\">Freelancer</a></a></span></span><span class=\"fbProfileBylineFragment\"><span class=\"fbProfileBylineIconContainer\"><i class=\"mrs fbProfileBylineIcon img sp_9pvis2 sx_ed189a\"></i></span><span class=\"fbProfileBylineLabel\">Studied Web Design at <a href=\"true\"><a href=\"https://www.facebook.com/pages/Universitatea-Tibiscus/242668875759811\" data-hovercard=\"/ajax/hovercard/page.php?id=242668875759811\">Universitatea Tibiscus</a></a></span></span><span class=\"fbProfileBylineFragment\"><span class=\"fbProfileBylineIconContainer\"><i class=\"mrs fbProfileBylineIcon img sp_9pvis2 sx_c1d4c8\"></i></span><span class=\"fbProfileBylineLabel\">Lives in <a href=\"true\"><a href=\"https://www.facebook.com/pages/Timi%C8%99oara-poland/107982459236366\" data-hovercard=\"/ajax/hovercard/page.php?id=107982459236366\">Timișoara, poland</a></a></span></span></div></div><div><div class=\"mts detailedsearch_actions\"><a href=\"/browse/mutual_friends/?uid=616226XXX\" rel=\"dialog\" ajaxify=\"/ajax/browser/dialog/mutual_friends/?uid=616226XXX\" onclick=\"if (event.button == 0) &#123; search_logged_ajax(&#123;&quot;ab&quot;:&quot;T_GS_BACKEND_ENTITY_LIMITATION&quot;,&quot;cururl&quot;:&quot;https:\\\\/\\\\/www.facebook.com\\\\/adrianasdzxc&quot;,&quot;fc&quot;:1,&quot;gc&quot;:0,&quot;id&quot;:616226XXX,&quot;init&quot;:&quot;s:unknown&quot;,&quot;is_friend&quot;:true,&quot;is_new_user&quot;:0,&quot;locale&quot;:&quot;en_US&quot;,&quot;o_type&quot;:1,&quot;original_q&quot;:&quot;adriantnt\\\\u0040yahoo.com&quot;,&quot;q&quot;:&quot;adriantnt\\\\u0040yahoo.com&quot;,&quot;rank&quot;:0,&quot;rc&quot;:0,&quot;sid&quot;:&quot;10000108681XXXX.3365508868..1&quot;,&quot;start&quot;:0,&quot;typeahead_sid&quot;:null,&quot;u&quot;:&quot;https:\\\\/\\\\/www.facebook.com\\\\/adrianasdzxc&quot;,&quot;t&quot;:&quot;c:mutual_friend&quot;&#125;); &#125;\" onmouseup=\"if (event.button != 0) &#123; search_logged_ajax(&#123;&quot;ab&quot;:&quot;T_GS_BACKEND_ENTITY_LIMITATION&quot;,&quot;cururl&quot;:&quot;https:\\\\/\\\\/www.facebook.com\\\\/adrianasdzxc&quot;,&quot;fc&quot;:1,&quot;gc&quot;:0,&quot;id&quot;:616226XXX,&quot;init&quot;:&quot;s:unknown&quot;,&quot;is_friend&quot;:true,&quot;is_new_user&quot;:0,&quot;locale&quot;:&quot;en_US&quot;,&quot;o_type&quot;:1,&quot;original_q&quot;:&quot;adriantnt\\\\u0040yahoo.com&quot;,&quot;q&quot;:&quot;adriantnt\\\\u0040yahoo.com&quot;,&quot;rank&quot;:0,&quot;rc&quot;:0,&quot;sid&quot;:&quot;10000108681XXXX.3365508868..1&quot;,&quot;start&quot;:0,&quot;typeahead_sid&quot;:null,&quot;u&quot;:&quot;https:\\\\/\\\\/www.facebook.com\\\\/adrianasdzxc&quot;,&quot;t&quot;:&quot;c:mutual_friend&quot;&#125;); &#125;\" role=\"button\">2 mutual friends</a> · <a href=\"/messages/adrianasdzxc\" ajaxify=\"/ajax/messaging/composer.php?ids%5B0%5D=616226XXX&amp;ref=search\" rel=\"dialog\" onclick=\"if (event.button == 0) &#123; search_logged_ajax(&#123;&quot;ab&quot;:&quot;T_GS_BACKEND_ENTITY_LIMITATION&quot;,&quot;cururl&quot;:&quot;https:\\\\/\\\\/www.facebook.com\\\\/adrianasdzxc&quot;,&quot;fc&quot;:1,&quot;gc&quot;:0,&quot;id&quot;:616226XXX,&quot;init&quot;:&quot;s:unknown&quot;,&quot;is_friend&quot;:true,&quot;is_new_user&quot;:0,&quot;locale&quot;:&quot;en_US&quot;,&quot;o_type&quot;:1,&quot;original_q&quot;:&quot;adriantnt\\\\u0040yahoo.com&quot;,&quot;q&quot;:&quot;adriantnt\\\\u0040yahoo.com&quot;,&quot;rank&quot;:0,&quot;rc&quot;:0,&quot;sid&quot;:&quot;10000108681XXXX.3365508868..1&quot;,&quot;start&quot;:0,&quot;typeahead_sid&quot;:null,&quot;u&quot;:&quot;https:\\\\/\\\\/www.facebook.com\\\\/adrianasdzxc&quot;,&quot;t&quot;:&quot;c:action&quot;&#125;); &#125;\" onmouseup=\"if (event.button != 0) &#123; search_logged_ajax(&#123;&quot;ab&quot;:&quot;T_GS_BACKEND_ENTITY_LIMITATION&quot;,&quot;cururl&quot;:&quot;https:\\\\/\\\\/www.facebook.com\\\\/adrianasdzxc&quot;,&quot;fc&quot;:1,&quot;gc&quot;:0,&quot;id&quot;:616226XXX,&quot;init&quot;:&quot;s:unknown&quot;,&quot;is_friend&quot;:true,&quot;is_new_user&quot;:0,&quot;locale&quot;:&quot;en_US&quot;,&quot;o_type&quot;:1,&quot;original_q&quot;:&quot;adriantnt\\\\u0040yahoo.com&quot;,&quot;q&quot;:&quot;adriantnt\\\\u0040yahoo.com&quot;,&quot;rank&quot;:0,&quot;rc&quot;:0,&quot;sid&quot;:&quot;10000108681XXXX.3365508868..1&quot;,&quot;start&quot;:0,&quot;typeahead_sid&quot;:null,&quot;u&quot;:&quot;https:\\\\/\\\\/www.facebook.com\\\\/adrianasdzxc&quot;,&quot;t&quot;:&quot;c:action&quot;&#125;); &#125;\" role=\"button\">Send message</a></div></div></div></div></div></div></div> --></code>\n") 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