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
  • 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

/
/
g

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"\@?T\(.*?\)" test_str = ("@{\n" " Layout = \"~/Views/Shared/_Layout.cshtml\";\n" " ViewBag.SeoTitle = T(\"PVC Kapı ve Pencere Sistemleri | Gedizpen\").ToString();\n" " ViewBag.MetaDescription = T(\"Dünyada PVC Kapı ve Pencere sistemlerini oluşturan parçaların tamamını üreten tek firma olan Winhouse'un pencere ve kapı ürünleri detayları için tıklayın!\").ToString();\n" "}\n\n" "<!-- =HomeSlider -->\n" "<section class=\"home-slider-section\">\n" " <div class=\"container\">\n" " <div class=\"home-slider-wrapper\">\n" " <div class=\"home-slider flexslider\">\n" " <ul class=\"slides\">\n" " @foreach (var slider in ContentManager.LoadByType(\"Slider\", CurrentCulture).Where(x => x.Status))\n" " {\n" " <li>\n" " @if (!string.IsNullOrEmpty(slider.Link))\n" " {\n" " <a href=\"@slider.Link\" target=\"@slider.LinkTarget\">\n" " <img src=\"@MediaService.GetContentRoute((int)slider.Id, \"SliderImage\").IfNotNull(x => StaticContent(x.Url))\" alt=\"@slider.Title\" data-desc=\"@slider.Description\">\n" " </a>\n" " }\n" " else\n" " {\n" " <img src=\"@MediaService.GetContentRoute((int)slider.Id, \"SliderImage\").IfNotNull(x => StaticContent(x.Url))\" alt=\"@slider.Title\" data-desc=\"@slider.Description\">\n" " }\n" " </li>\n" " }\n" " </ul>\n" " </div>\n" " </div>\n" " </div>\n" "</section>\n" "<!-- =HomeSlider -->\n\n" "<!-- =HomeWidgets -->\n" "<section class=\"home-widgets-section\">\n" " <div class=\"container\">\n" " <div class=\"inner clearfix\">\n" " <div class=\"home-widget home-widget-1\">\n" " <h2 class=\"heading\">@T(\"Haberler &amp; Duyurular\")</h2>\n" " <div class=\"widget-content\">\n" " <div class=\"news-slider-wrapper\">\n" " <div class=\"news-slider flexslider\" data-prev=\".news-slider-wrapper .prev\" data-next=\".news-slider-wrapper .next\">\n" " <ul class=\"slides\">\n\n" " @foreach (var announcement in ContentManager.LoadByType(\"Announcement\", CurrentCulture).Where(x => x.Status && x.ContentCategory.GroupKey == Guid.Parse(\"430D75FE-BAB8-4566-AE56-A06C515CE6D6\")).OrderByDescending(x => x.CreatedDate).Take(3))\n" " {\n" " <li><a href=\"@ContentRouteManager.GetContentRouteUrl(announcement.Id)\">@(((string)announcement.SpotText).TruncateAtWord(110))<img class=\"figure\" src=\"@MediaService.GetContentRoute((int)announcement.Id, \"AnnouncementImage\").IfNotNull(x => StaticContent(x.Url))\" alt=\"@announcement.Title\"></a></li>\n" " }\n" " </ul>\n" " </div>\n" " <a class=\"prev arrow ir\" href=\"javascript:;\"><span>&laquo;</span></a>\n" " <a class=\"next arrow ir\" href=\"javascript:;\"><span>&raquo;</span></a>\n" " </div>\n" " <a class=\"read-more\" href=\"@GetPreDefinedPageUrl(\"Index\", \"Announcement\")\">@T(\"Tüm Haberler\")</a>\n" " </div>\n" " </div>\n" " <div class=\"home-widget home-widget-2\">\n" " <h2 class=\"heading\">@T(\"Size En Yakın Bayi Nerede ?\")</h2>\n" " <div class=\"widget-content\">\n" " <form class=\"nearest-dealer-search-form\">\n" " <div class=\"input-wrapper js-select-wrapper\">\n" " @*@Html.DropDownListFor(x => x.City, Model.Cities, \"Lütfen il seçiniz...\", new { @class = \"style\" })*@\n" " @Html.DropDownList(\"City\", T(\"Lütfen il seçiniz...\").ToString())\n" " </div>\n" " <div class=\"input-wrapper js-select-wrapper\">\n" " @*@Html.DropDownListFor(x => x.County, Model.Counties, \"Önce il seçiniz...\", new { @class = \"style\" })*@\n" " @Html.DropDownList(\"County\", T(\"Önce il seçiniz...\").ToString())\n" " </div>\n" " <div class=\"submit-wrapper\">\n" " <a href=\"javascript:;\" class=\"theme-button\">\n" " <span>@T(\"ARA\")</span>\n" " </a>\n" " </div>\n" " </form>\n" " </div>\n" " </div>\n" " <div class=\"home-widget home-widget-3\">\n" " <h2 class=\"heading\">@T(\"Pencere Mühendislik Hesaplamaları\")</h2>\n" " <div class=\"widget-content\">\n" " <p>@T(\"Pencere uygulamasında ihtiyaç duyduğunuz pencere mühendislik hesaplamalarını yapabilirsiniz.\")</p>\n" " <a class=\"read-more\" href=\"@GetPreDefinedPageUrl(\"WindowCalculations\", \"Calculations\")\">@T(\"Detaylı Bilgi\")</a>\n" " </div>\n" " </div>\n" " </div>\n" " </div>\n" "</section>\n" "<!-- =HomeWidgets -->\n\n" "<!-- =FeaturedLinks -->\n" "<div class=\"featured-links-section\">\n" " <div class=\"container\">\n" " <div class=\"inner clearfix\">\n" " <div class=\"featured-links\">\n" " <a href=\"@ContentRouteManager.GetContentRouteUrl(\"9ce86817-8a24-44b9-a32a-4dff918ada50\")\" class=\"featured-link featured-link-1\">\n" " <span class=\"icon\">\n" " <i class=\"theme-icon-drill\"></i>\n" " <span></span>\n" " </span>\n" " <strong class=\"title\">\n" " @T(\"<span>Pencere</span> <span>Montaj Uygulaması</span>\")\n" " </strong>\n" " </a>\n" " <a href=\"@ContentRouteManager.GetContentRouteUrl(\"95bd8a0d-d53b-42cb-9372-411c28d2b378\")\" class=\"featured-link featured-link-2\">\n" " <span class=\"icon\">\n" " <i class=\"theme-icon-home\"></i>\n" " <span></span>\n" " </span>\n" " <strong class=\"title\">\n" " @T(\"<span>Size Özel</span> <span>Pencereler</span>\")\n" " </strong>\n" " </a>\n" " <a href=\"@ContentRouteManager.GetContentRouteUrl(\"d0a6cecf-82c6-4705-91b4-8902073ab627\")\" class=\"featured-link featured-link-3\">\n" " <span class=\"icon\">\n" " <i class=\"theme-icon-window\"></i>\n" " <span></span>\n" " </span>\n" " <strong class=\"title\">\n" " @T(\"<span>Pencere</span> <span>Animasyonları</span>\")\n" " </strong>\n" " </a>\n" " <a href=\"@ContentRouteManager.GetContentRouteUrl(\"da4e73a9-d845-433e-bc04-8844557cdbb9\")\" class=\"featured-link featured-link-4\">\n" " <span class=\"icon\">\n" " <i class=\"theme-icon-check\"></i>\n" " <span></span>\n" " </span>\n" " <strong class=\"title\">\n" " @T(\"<span>FUDEL Akredite</span> <span>Pencere Laboratuarı</span>\")\n" " </strong>\n" " </a>\n" " </div>\n" " </div>\n" " </div>\n" "</div>\n" "<!-- =FeaturedLinks -->\n\n" "@section Head{\n" " @Styles.Render(\"~/assets/css/plugins/jquery.flexslider.min.css\")\n" " @Styles.Render(\"~/assets/css/plugins/jquery.mcustomscrollbar.css\")\n" "}\n\n" "@section Plugins{\n" " @Scripts.Render(\"~/assets/js/plugins/jquery.flexslider.min.js\")\n" " @Scripts.Render(\"~/assets/js/plugins/jquery.mcustomscrollbar.js\")\n" "}") matches = re.finditer(regex, test_str) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.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