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

/
/
g

Test String

Code Generator

Generated Code

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "\\@?T\\(.*?\\)"; final String string = "@{\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" + "}"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html