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

r"
"
mg

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 = "var[\\s]+data[\\s]?=[\\s]?(\\{[^;]*\\});"; final String string = "<link rel=\"shortcut icon\" href=\"/static/frontend/images/favicons/favicon.ico\"/>\n" + " <meta name=\"og:title\" content=\"Продажа 3-комнатной квартиры - №25234817: Абылай хана — Маметова, Алматы, Алмалинский р-н — за 25500000 — Крыша\"/>\n" + " <meta name=\"og:url\" content=\"https://krisha.kz/a/show/25234817\"/>\n" + " <meta name=\"og:image\" content=\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/1-400x300.jpg\"/>\n" + " <meta name=\"og:site_name\" content=\"Krisha.kz\"/>\n" + " <meta property=\"fb:pages\" content=\"453858631376956\" />\n" + " <script >\n" + " var data = {\"advert\":{\"id\":25234817,\"storage\":\"live\",\"commentsType\":\"adv\",\"isCommentable\":true,\"isCommentableByEveryone\":false,\"isOnMap\":true,\"hasPrice\":true,\"photos\":[{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/1-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/8-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/9-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/10-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/11-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/12-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/13-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/14-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/15-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/16-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/17-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/18-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/19-full.jpg\",\"w\":900,\"h\":900},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/20-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/21-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/22-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/23-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/24-full.jpg\",\"w\":1127,\"h\":900},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/25-full.jpg\",\"w\":1200,\"h\":800},{\"src\":\"https://alaps-photos-kr.kcdn.kz/1d/30a8f294c49e32da5be7040661cadf/26-full.jpg\",\"w\":1200,\"h\":800}],\"map\":{\"lat\":43.267643,\"lon\":76.939123,\"zoom\":15,\"type\":\"yandex#map\"}},\"analysisUrl\":\"/analytics/aPriceAnalysis/\",\"creditIsEnabled\":true,\"infrastructure\":{\"data\":{\"data\":{\"tags\":{\"pharmacy\":{\"title\":\"Аптеки\"},\"hospital\":{\"title\":\"Поликлиники\"},\"kindergarten\":{\"title\":\"Детсады\"},\"school\":{\"title\":\"Школы и Вузы\"},\"cafe\":{\"title\":\"Рестораны, кафе\"},\"cinema\":{\"title\":\"Кино и театры\"},\"shop\":{\"title\":\"Магазины и ТРК\"}},\"regions\":[{\"id\":67,\"title\":\"Алматы\",\"bounds\":[[43.469093,76.72599],[43.462692,77.1084],[43.108051,77.096182],[43.114387,76.715991],[43.469093,76.72599]],\"rubrics\":{\"cafe\":[\"9429531978963634\",\"9429531978891425\",\"9429531978891429\",\"9429531978891426\",\"9429531978891428\",\"9429531978891430\",\"9429531978907055\"],\"cinema\":[\"9429531978891456\",\"9429531978891463\"],\"pharmacy\":[\"9429531978891471\"],\"hospital\":[\"9429531978891465\",\"9429531978891488\",\"9429531978915029\",\"9429531978891466\",\"9429531978891489\"],\"school\":[\"9429531978891494\",\"9429531978891947\",\"9429531978891495\",\"9429531978891510\",\"9429531978906551\",\"9429531978891496\",\"9429531978891512\",\"9429531978891509\"],\"kindergarten\":[\"9429531978891501\",\"9429531979001669\"],\"shop\":[\"9429531978891637\",\"9429531978891875\"]}},{\"id\":68,\"title\":\"Астана\",\"bounds\":[[51.371885,71.18796],[51.35684,71.882791],[50.934375,71.856572],[50.949196,71.168047],[51.371885,71.18796]],\"rubrics\":{\"cafe\":[\"9570269467318962\",\"9570269467246753\",\"9570269467246757\",\"9570269467246754\",\"9570269467246756\",\"9570269467246758\",\"9570269467262383\"],\"cinema\":[\"9570269467246784\",\"9570269467246791\"],\"pharmacy\":[\"9570269467246799\"],\"hospital\":[\"9570269467246793\",\"9570269467246816\",\"9570269467270357\",\"9570269467246794\",\"9570269467246817\"],\"school\":[\"9570269467246822\",\"9570269467247275\",\"9570269467246823\",\"9570269467246838\",\"9570269467261879\",\"9570269467246824\",\"9570269467246837\"],\"kindergarten\":[\"9570269467246829\",\"9570269467356997\"],\"shop\":[\"9570269467246965\",\"9570269467247203\"]}},{\"id\":84,\"title\":\"Караганда\",\"bounds\":[[50.132623,73.394974],[49.658415,73.41063],[49.64993,72.880917],[50.123995,72.860052],[50.132623,73.394974]],\"rubrics\":{\"cafe\":[\"11822069281004210\",\"11822069280932001\",\"11822069280932005\",\"11822069280932002\",\"11822069280932004\",\"11822069280932006\",\"11822069280947631\"],\"cinema\":[\"11822069280932032\",\"11822069280932039\"],\"pharmacy\":[\"11822069280932047\"],\"hospital\":[\"11822069280932041\",\"11822069280932064\",\"11822069280932042\",\"11822069280932065\"],\"school\":[\"11822069280932070\",\"11822069280932523\",\"11822069280932071\",\"11822069280932086\",\"11822069280947127\",\"11822069280932072\",\"11822069280932085\"],\"kindergarten\":[\"11822069280932077\",\"11822069281042245\"],\"shop\":[\"11822069280932213\",\"11822069280932451\"]}},{\"id\":111,\"title\":\"Павлодар\",\"bounds\":[[52.439519,76.677763],[52.430303,77.2347],[52.005015,77.213446],[52.014092,76.661799],[52.439519,76.677763]],\"rubrics\":{\"cafe\":[\"15621981466525857\",\"15621981466525861\",\"15621981466525858\",\"15621981466525860\",\"15621981466525862\",\"15621981466541487\"],\"cinema\":[\"15621981466525888\",\"15621981466525895\"],\"pharmacy\":[\"15621981466525903\"],\"hospital\":[\"15621981466525897\",\"15621981466525920\",\"15621981466549461\",\"15621981466525898\",\"15621981466525921\"],\"school\":[\"15621981466525926\",\"15621981466526379\",\"15621981466525927\",\"15621981466525942\",\"15621981466540983\",\"15621981466525928\",\"15621981466525941\"],\"kindergarten\":[\"15621981466525933\",\"15621981466636101\"],\"shop\":[\"15621981466526069\",\"15621981466526307\"]}},{\"id\":162,\"title\":\"Уральск\",\"bounds\":[[51.284431,51.526154],[51.109229,51.567598],[51.110327,51.255488],[51.285243,51.256457],[51.284431,51.526154]],\"rubrics\":{\"cafe\":[\"22799593372719794\",\"22799593372647585\",\"22799593372647589\",\"22799593372647586\",\"22799593372647588\",\"22799593372647590\",\"22799593372663215\"],\"cinema\":[\"22799593372647616\",\"22799593372647623\"],\"pharmacy\":[\"22799593372647631\"],\"hospital\":[\"22799593372647625\",\"22799593372647648\",\"22799593372671189\",\"22799593372647649\"],\"school\":[\"22799593372647654\",\"22799593372648107\",\"22799593372647670\",\"22799593372662711\",\"22799593372647656\",\"22799593372647669\"],\"kindergarten\":[\"22799593372647661\",\"22799593372757829\"],\"shop\":[\"22799593372647797\",\"22799593372648035\"]}},{\"id\":91,\"title\":\"Усть-Каменогорск\",\"bounds\":[[49.862906,82.444837],[50.059192,82.450724],[50.054212,82.805717],[49.857959,82.798391],[49.862906,82.444837]],\"rubrics\":{\"cafe\":[\"12807231699491506\",\"12807231699419297\",\"12807231699419301\",\"12807231699419298\",\"12807231699419300\",\"12807231699419302\",\"12807231699434927\"],\"cinema\":[\"12807231699419328\",\"12807231699419335\"],\"pharmacy\":[\"12807231699419343\"],\"hospital\":[\"12807231699419337\",\"12807231699419360\",\"12807231699442901\",\"12807231699419338\",\"12807231699419361\"],\"school\":[\"12807231699419366\",\"12807231699419819\",\"12807231699419382\",\"12807231699434423\",\"12807231699419368\",\"12807231699419384\",\"12807231699419381\"],\"kindergarten\":[\"12807231699419373\",\"12807231699529541\"],\"shop\":[\"12807231699419509\",\"12807231699419747\"]}},{\"id\":161,\"title\":\"Шымкент\",\"bounds\":[[42.43852,69.416245],[42.436468,69.802137],[42.242484,69.799675],[42.244521,69.414967],[42.43852,69.416245]],\"rubrics\":{\"cafe\":[\"22658855884364466\",\"22658855884292257\",\"22658855884292261\",\"22658855884292258\",\"22658855884292260\",\"22658855884292262\",\"22658855884307887\"],\"cinema\":[\"22658855884292288\",\"22658855884292295\"],\"pharmacy\":[\"22658855884292303\"],\"hospital\":[\"22658855884292297\",\"22658855884292320\",\"22658855884315861\",\"22658855884292298\",\"22658855884292321\"],\"school\":[\"22658855884292326\",\"22658855884292779\",\"22658855884292327\",\"22658855884292342\",\"22658855884307383\",\"22658855884292328\",\"22658855884292341\"],\"kindergarten\":[\"22658855884292333\",\"22658855884402501\"],\"shop\":[\"22658855884292469\",\"22658855884292707\"]}}]},\"baseUrl\":\"https://catalog.api.2gis.ru/2.0/\",\"key\":\"rutogo9647\"},\"button\":\"Инфраструктура\",\"title\":\"Инфраструктура\",\"user\":\"_2gis_user\",\"sid\":\"_2gis_session\"},\"crime\":{\"api\":\"https://api.krisha.kz/geodata/crime\",\"button\":\"Преступность\",\"title\":\"Показатели преступности\"},\"svgIconsUrl\":\"//krisha.kz/static/frontend/svg/svg-symbols.svg\",\"svgIconsDate\":1497612417,\"app\":\"Frontend\",\"baseHostname\":\"krisha.kz\",\"cookieDomain\":\".krisha.kz\",\"isRemoteResourcesEnabled\":true,\"isDebug\":false,\"route\":\"a:show\",\"controller\":\"a\",\"action\":\"show\",\"user\":{\"isGuest\":true,\"isPro\":false,\"isCompany\":false,\"id\":null,\"locale\":\"ru\",\"xdmAssetUrl\":\"https://id.kolesa.kz/authToken.js\"},\"photoHost\":\"photos-kr.kcdn.kz\",\"views\":{\"location\":\"98fb0972\"}};\n" + " </script>\n" + " <!--[if lt IE 9]>\n" + " <script src=\"//krisha.kz/static/frontend/js/main-vendor-legacy-20170616172657.js\"></script>\n" + " <![endif]-->\n" + " <link rel=\"stylesheet\" type=\"text/css\" href=\"//krisha.kz/static/frontend/css/main-vendor.css\" />\n" + "<link rel=\"stylesheet\" type=\"text/css\" href=\"//krisha.kz/static/frontend/css/main-20170616172657.css\" />\n\n" + " \n" + " \n" + " <script type=\"text/javascript\" src=\"//code-br.kcdn.kz/js/client.min.js\" charset=\"utf-8\"></script>\n\n" + " <script type=\"application/javascript\">var client = kolesaBannerClient;\n" + "var YaDirectParams = {\n" + " stat_id: 5,\n" + " ad_format: \"direct\",\n" + " font_size: 1,\n" + " type: \"oldHorizontal\",\n" + " limit: 1,\n" + " title_font_size: 3,\n" + " links_underline: true,\n" + " site_bg_color: \"FFF2CF\",\n" + " bg_color: \"FFF2CF\",\n" + " title_color: \"996633\",\n" + " url_color: \"0066CC\",\n" + " text_color: \"996633\",\n" + " hover_color: \"FF0000\",\n" + " favicon: true,\n" + " no_sitelinks: true\n" + " };\n" + "client.setSiteId(12).enableSingleRequest()\n" + " .addTag('category', 'Продажа')\n" + " .addTag('type', 'Квартиры')\n" + " .addTag('city', 'Алматы')\n" + " .addTag('url', '/a/show/*')\n" + " .addTag('price', '18000000-36000000')\n" + " .addTag('gender', '')"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); 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