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

r"
"

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"href=\"(.+?)\">ذهاب الان</a>" test_str = ("\n" "<html xmlns=\"http://www.w3.org/1999/xhtml\" dir=\"rtl\" lang=\"ar\">\n" "<head profile=\"http://gmpg.org/xfn/11\">\n" "<base href=\"http://movizland.com\"/>\n" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n" "<title itemprop='name'>مشاهدة فيلم Steve Jobs 2015 مترجم بجودة 1080p BluRay </title>\n" "<meta name=\"viewport\" content=\"width=device-width\"/>\n" "<meta http-equiv=\"Content-Language\" content=\"en-us,ar\"/>\n" "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n" "<meta name=\"description\" content=\"Movizland - موفيز لاند - فيلم&nbsp; Steve Jobs 2015 BluRay, مشاهدة فيلم Steve Jobs 2015 BluRay, تحميل , مشاهدة Steve Jobs 2015 BluRay اون لاين, Steve Jobs 2015 BluRay مترجم بلوراي, تحميل مباشر فيلم&nbsp; Steve Jobs 2015 BluRay, مشاهدة مباشرة لفيلم&nbsp; Steve Jobs 2015 BluRay, شاهد اون لاين فيلم&nbsp; Steve Jobs 2015 BluRay, فيلم&nbsp; Steve Jobs 2015 BluRay كامل مترجم, فيلم&nbsp; Steve Jobs 2015 BluRay مترجم كامل, تنزيل فيلم Steve Jobs 2015 BluRay, مشاهدة فيلم Steve Jobs 2015 BluRay, فيلم Steve Jobs 2015 BluRay بجودة عالية\">\n" "<meta name=\"keywords\" content=\"Movizland,موفيز لاند,موفيزلاند,أفلام اجنبية,افلام,دراما,سيره ذاتيه,\">\n" "<meta http-equiv=\"Content-Language\" content=\"ar-eg\"/>\n" "<meta http-equiv=\"Cache-Control\" content=\"no-cache\"/>\n" "<meta http-equiv=\"Pragma\" content=\"no-cache\"/>\n" "<meta name=\"Expires\" content=\"0\"/>\n" "<meta name=\"rating\" content=\"General\"/>\n" "<meta name=\"robots\" content=\"index, follow\"/>\n" "<meta name=\"robots\" content=\"NOODP,NOYDIR\"/>\n" "<meta name=\"revisit-after\" content=\"1 hour\"/>\n" "<meta name=\"distribution\" content=\"Global\"/>\n" "<meta name=\"classification\" content=\"All\"/>\n" "<meta name=\"googlebot\" content=\"archive\"/>\n" "<meta name=\"resource-type\" content=\"document\"/>\n" "<meta name=\"author\" content=\"Movizland .Com\"/>\n" "<meta property=\"og:type\" content=\"article\"/>\n" "<meta property=\"og:url\" content=\"http://movizland.com/movies/%d9%81%d9%8a%d9%84%d9%85-steve-jobs-2015-%d9%85%d8%aa%d8%b1%d8%ac%d9%85-%d8%a8%d8%ac%d9%88%d8%af%d8%a9-1080p-bluray/\"/>\n" "<script type=\"text/javascript\">\n" "//<![CDATA[\n" "try{if (!window.CloudFlare) {var CloudFlare=[{verbose:0,p:0,byc:0,owlid:\"cf\",bag2:1,mirage2:0,oracle:0,paths:{cloudflare:\"/cdn-cgi/nexp/dok3v=1613a3a185/\"},atok:\"2841200b99e0503213236eb6beec5cc0\",petok:\"0b0dd91ad9f44b84332bd5593c41a44e9283c53a-1454659108-1800\",zone:\"movizland.com\",rocket:\"a\",apps:{},sha2test:0}];document.write('<script type=\"text/javascript\" src=\"//ajax.cloudflare.com/cdn-cgi/nexp/dok3v=38857570ac/cloudflare.min.js\"><'+'\\/script>');}}catch(e){};\n" "//]]>\n" "</script>\n" "<link itemprop=\"url\" rel=\"canonical\" href=\"http://movizland.com/movies/%d9%81%d9%8a%d9%84%d9%85-steve-jobs-2015-%d9%85%d8%aa%d8%b1%d8%ac%d9%85-%d8%a8%d8%ac%d9%88%d8%af%d8%a9-1080p-bluray/\"/>\n" "<meta property=\"og:title\" content=\"فيلم Steve Jobs 2015 مترجم بجودة 1080p BluRay\"/>\n" "<meta property=\"og:image:secure_url\" content=\"\"/>\n" "<meta property=\"og:image\" content=\"http://movizland.com/wp-content/uploads/steve_jobs_ver2-1.jpg\"/>\n" "<meta property=\"og:site_name\" content=\"Movizland\"/>\n" "<meta property=\"og:description\" content=\"Movizland - موفيز لاند - فيلم&nbsp; Steve Jobs 2015 BluRay, مشاهدة فيلم Steve Jobs 2015 BluRay, تحميل , مشاهدة Steve Jobs 2015 BluRay اون لاين, Steve Jobs 2015 BluRay مترجم بلوراي, تحميل مباشر فيلم&nbsp; Steve Jobs 2015 BluRay, مشاهدة مباشرة لفيلم&nbsp; Steve Jobs 2015 BluRay, شاهد اون لاين فيلم&nbsp; Steve Jobs 2015 BluRay, فيلم&nbsp; Steve Jobs 2015 BluRay كامل مترجم, فيلم&nbsp; Steve Jobs 2015 BluRay مترجم كامل, تنزيل فيلم Steve Jobs 2015 BluRay, مشاهدة فيلم Steve Jobs 2015 BluRay, فيلم Steve Jobs 2015 BluRay بجودة عالية\">\n" "<link rel=\"pingback\" href=\"http://movizland.com/xmlrpc.php\"/>\n" "<link rel=\"alternate\" type=\"application/rss+xml\" href=\"http://movizland.com/feed\" title=\"Movizland .Com\"/>\n" "<link href='http://fonts.googleapis.com/css?family=Niconne' rel='stylesheet' type='text/css'/>\n" "<script type=\"text/rocketscript\" data-rocketsrc=\"http://movizland.com/wp-content/themes/new/js/jquery-1.8.2.min.js\"></script>\n" "<link rel=\"stylesheet\" type=\"text/css\" href=\"http://movizland.com/wp-content/themes/new/style.css\"/>\n" "<link rel=\"stylesheet\" type=\"text/css\" href=\"http://movizland.com/wp-content/themes/new/css/font-awesome.min.css\"/>\n" "<script type=\"application/ld+json\">\n" " { \"@context\" : \"http://schema.org\",\n" " \"@type\" : \"WebSite\",\n" " \"name\" : \"Movizland\",\n" " \"alternateName\" : \"Movizland.Com\",\n" " \"url\" : \"http://movizland.com\"\n" " }\n" " </script>\n" "</head>\n" "<body style=\"background-image:url('http://movizland.com/wp-content/uploads/thehungergames.jpg');\">\n" "<header>\n" "<div class=\"dropmenu-nav\">\n" "<li><a href=\"http://movizland.com/\">الرئيسية</a> </li>\n" "<li><a href=\"http://vb.movizland.com/\">المنتدي</a> </li>\n" "<li><a href=\"http://vb.movizland.com/f15\">طلبات الافلام</a> </li>\n" "<li><a href=\"http://vb.movizland.com/f20\">مواضيع تهمك</a> </li>\n" "<li><a href=\"http://movizland.com/vb/sendmessage.php\">اتصل بنا</a> </li>\n" "</div>\n" "<div class=\"cpanel\">\n" "<li class=\"btn-red future-btn\"> <a href=\"http://movizland.com/vb/t11910\"> اشتراك مميز <span style=\"text-align: center;font-size: 13px;display: block;margin-top: -4px;margin-bottom: -3px;\">خواص بلا حدود</span> </a> </li>\n" "<li class=\"btn-red app-btn\"> <a href=\"http://www.movizland.com/MovizLand_1.0.apk\"> تحميل التطبيق<br> <span style=\"text-align: center;font-size: 13px;display: block;margin-top: -4px;margin-bottom: -3px;\">لموبايل اندرويد</span> </a> </li>\n" "</div>\n" "<div class=\"center\">\n" "<div class=\"tiny-stars\"><img src=\"http://movizland.com/wp-content/themes/new/img/stars2.svg\" alt=\"Movizland .Com\"></div>\n" "<div class=\"tiny-stars middle-stars\"><img src=\"http://movizland.com/wp-content/themes/new/img/stars3.svg\" alt=\"Movizland .Com\"></div>\n" "<div class=\"planet-big centered\">\n" " <span class=\"round round-1\"></span> <span class=\"round round-2\"></span> <span class=\"round round-3\"></span> <span class=\"round round-4\"></span> <span class=\"round round-5\"></span> \n" "</div>\n" " \n" "</div>\n" "<div id=\"poster\">\n" "<div id=\"letter-container\" class=\"letter-container\">\n" "<h2> <a href=\"http://movizland.com/\"><span class=\"char1\">M</span><span class=\"char2\">o</span><span class=\"char3\">v</span><span class=\"char4\">i</span><span class=\"char5\">z</span><span class=\"char6\"> </span><span class=\"char7\">L</span><span class=\"char8\">a</span><span class=\"char9\">n</span><span class=\"char10\">d</span></a> <a href=\"http://movizland.com/\" style=\"font-size:52px\"><span class=\"char1\">A</span><span class=\"char2\">l</span><span class=\"char3\">l</span><span class=\"char4\"> </span><span class=\"char5\">M</span><span class=\"char6\">o</span><span class=\"char7\">v</span><span class=\"char8\">i</span><span class=\"char9\">e</span><span class=\"char10\">s</span><span class=\"char11\"> </span><span class=\"char12\">I</span><span class=\"char13\">n</span><span class=\"char14\"> </span><span class=\"char15\">Y</span><span class=\"char16\">o</span><span class=\"char17\">u</span><span class=\"char18\">r</span><span class=\"char19\"> </span><span class=\"char20\">H</span><span class=\"char21\">a</span><span class=\"char22\">n</span><span class=\"char23\">d</span></a> </h2>\n" "</div>\n" "</div>\n" "<div class=\"holderB\"></div>\n" "<style>div#title-movie>strong{position:absolute;top:-17px;right:14px;background:#81011D;color:white;font-weight:normal;padding:3px 10px;border-radius:4px;}div#title-movie{position:absolute;bottom:30px;right:50%;margin-right:-500px;background:black;border-radius:10px;padding:21px 20px 20px;font-size:14px;font-family:Flat;width:420px;border:2px solid #151515;box-shadow:0px 1px 26px black;}</style>\n" "</header>\n" "<div class=\"wrap\"><main class=\"home-boxes\" id=\"seccion2\">\n" " \n" "<script data-cfasync=\"false\" type=\"text/javascript\" src=\"//go.onclasrv.com/apu.php?zoneid=496414\"></script>\n" "<script type=\"text/rocketscript\">\n" "var adParams = {p: '60161217', serverdomain: 'wmedia' , numOfTimes: '1',duration: '5',period: 'minute' };\n" "</script>\n" "<script type=\"text/rocketscript\" data-rocketsrc='http://cdn.waframedia8.com/wmedia/tags/xpopup/xpopup.js?ap=1303'></script>\n" "<div class=\"movie-single\">\n" "<h2 class=\"title-ribbon\">\n" "<span></span>\n" "<strong>\n" "جديد\n" "</strong>\n" "<em class=\"afters\"></em>\n" "<em class=\"befores\">\n" "فيلم Steve Jobs 2015 مترجم بجودة 1080p BluRay </em>\n" "</h2>\n" "<div class=\"ad\">\n" "<script type=\"text/rocketscript\">\n" "var adParams = {p: '60401138', size: '728x90', serverdomain: 'wmedia' };\n" "</script>\n" "<script type=\"text/rocketscript\" data-rocketsrc='http://cdn.waframedia8.com/wmedia/tags/xbanner/xbanner.js?ap=1300'></script></div>\n" "<div class=\"ad-vertical\"><SCRIPT data-cfasync=\"false\" SRC=\"http://bdv.bidvertiser.com/BidVertiser.dbm?pid=551769&bid=1744544\" TYPE=\"text/javascript\"></SCRIPT></div>\n" "<div class=\"poster-movie\">\n" "<a href=\"http://vb.movizland.com/t30586\"><img width=\"490\" height=\"640\" src=\"http://movizland.com/wp-content/uploads/steve_jobs_ver2-1-490x640.jpg\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"steve_jobs_ver2\"/></a>\n" "</div>\n" "<div class=\"box-content\" style=\"color: white;font-family: Flat , Arial;\">\n" "فيلم&nbsp; Steve Jobs 2015 BluRay, مشاهدة فيلم Steve Jobs 2015 BluRay, تحميل , مشاهدة Steve Jobs 2015 BluRay اون لاين, Steve Jobs 2015 BluRay مترجم بلوراي, تحميل مباشر فيلم&nbsp; Steve Jobs 2015 BluRay, مشاهدة مباشرة لفيلم&nbsp; Steve Jobs 2015 BluRay, شاهد اون لاين فيلم&nbsp; Steve Jobs 2015 BluRay, فيلم&nbsp; Steve Jobs 2015 BluRay كامل مترجم, فيلم&nbsp; Steve Jobs 2015 BluRay مترجم كامل, تنزيل فيلم Steve Jobs 2015 BluRay, مشاهدة فيلم Steve Jobs 2015 BluRay, فيلم Steve Jobs 2015 BluRay بجودة عالية <div style=\"height:10px;\"></div>\n" "<btns class=\"btns-asni-anim-1\">\n" "<span>نوع الفيلم</span>\n" "<div class=\"fortermS\">\n" "<a href=\"http://movizland.com/all/%d8%af%d8%b1%d8%a7%d9%85%d8%a7/\" title=\"افلام دراما\">دراما</a>\n" "<a href=\"http://movizland.com/all/%d8%b3%d9%8a%d8%b1%d9%87-%d8%b0%d8%a7%d8%aa%d9%8a%d9%87/\" title=\"افلام سيره ذاتيه\">سيره ذاتيه</a>\n" "</div>\n" "</btns>\n" "<btns class=\"btns-asni-anim-2\">\n" "<span>قسم الفيلم</span>\n" "<div class=\"fortermS\">\n" "<a href=\"http://movizland.com/cat/foreign/\" title=\"قسم أفلام اجنبية\">أفلام اجنبية</a>\n" "<a href=\"http://movizland.com/cat/movies/\" title=\"قسم افلام\">افلام</a>\n" "</div>\n" "</btns>\n" "<div class=\"progress\">\n" "<a class=\"RedirecTliNK\" style=\"\n" " background: rgb(173, 0, 79);\n" " margin: 10px auto 0;\n" " font-family: Flat;\n" " border: 2px solid rgba(255, 255, 255, 0.27);\n" " padding: 7px 15px;\n" " font-size: 25px;\" href=\"http://moshahda.net/lw44qevnqkn9.html\">ذهاب الان</a>\n" "</div>\n" "<div class=\"ad\">\n" " \n" " \n" "<script type=\"text/rocketscript\">\n" "var adParams = {p: '70248929', size: '300x250', serverdomain: 'wmedia' };\n" "</script>\n" "<script type=\"text/rocketscript\" data-rocketsrc='http://cdn.waframedia8.com/wmedia/tags/xbanner/xbanner.js?ap=1300'></script>\n" "</div>\n" "</div>\n" "<div class=\"ad-vertical-2\"><SCRIPT data-cfasync=\"false\" SRC=\"http://bdv.bidvertiser.com/BidVertiser.dbm?pid=551769&bid=1744544\" TYPE=\"text/javascript\"></SCRIPT></div>\n" "</div>\n" "<style type=\"text/css\">.progress{float:left;}.histats{clear:both;}</style>\n" "<script type=\"text/rocketscript\">\n" "var adParams = {p: '70161427', closeButton: 'Left' , backgroundColor: 'transparent', size: '320x50',popOnClose:'true', serverdomain: 'wafra',period: 'minute', numOfTimes: '1',duration: '2' };\n" "</script>\n" "<script type=\"text/rocketscript\" data-rocketsrc='http://cdn.waframedia8.com/wafra/tags/xcatfish/xcatfish.js?ap=1301'></script>\n" "</div> <div class=\"aligncenter histats\"> <script type=\"text/rocketscript\">(function() {var _fbq = window._fbq || (window._fbq = []); if (!_fbq.loaded) {var fbds = document.createElement('script'); fbds.async = true; fbds.src = '//connect.facebook.net/en_US/fbds.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(fbds, s); _fbq.loaded = true; } })(); window._fbq = window._fbq || []; window._fbq.push(['track', '6022448280372', {'value':'0.00','currency':'USD'}]); </script> <noscript><img alt=\"\" height=\"1\" width=\"1\" alt=\"facebook\" style=\"display:none\" src=\"https://www.facebook.com/tr?ev=6022448280372&amp;cd[value]=0.00&amp;cd[currency]=USD&amp;noscript=1\"/></noscript> <script type=\"text/rocketscript\"> (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-51106521-2', 'auto'); ga('send', 'pageview'); </script>\n" " \n" "<a href=\"http://www.histats.com\" alt=\"page hit counter\" target=\"_blank\">\n" "<embed src=\"http://s10.histats.com/6.swf\" flashvars=\"jver=1&acsid=2308846&domi=4\" quality=\"high\" width=\"200\" height=\"40\" name=\"6.swf\" align=\"middle\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" wmode=\"transparent\"/></a>\n" "<img src=\"http://sstatic1.histats.com/0.gif?2308846&101\" alt=\"free html hit counter\" border=\"0\">\n" " </div> <div class=\"footer\"> <div class=\"copyrights\"> <a href=\"http://movizland.com\" title=\"Movizland .Com\">Movizland.com</a> </div> <div class=\"design\"> تصميم و برمجة <a href=\"http://www.yourcolor.net\" title=\"تصميم مواقع | برمجة خاصة | برمجة ووردبريس | استضافة\" alt=\"تصميم و برمجة و استضافة\">YourColor.net</a> </div> </div> <div id=\"overlay-closes\" style=\"display:none;\"></div> </body> </html>\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