Regular Expressions 101

Save & Share

  • Regex Version: ver. 3
  • 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

/
/
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 = ">Temperature<.*\\n.*>(.+?) °C<"; final String string = "\n" + "<!doctype html>\n" + "<html lang=\"ru\">\n" + "<head>\n" + " <meta charset=\"UTF-8\">\n" + " <title>Текущая погода в Сокольниках, Москва. Архив погоды.</title>\n" + " <link rel=\"ICON\" href=\"/favicon.ico\">\n" + " <link rel=\"stylesheet\" href=\"/css/reset.css\">\n" + " <link rel=\"stylesheet\" href=\"/css/styles-new.css\">\n" + " <link rel=\"stylesheet\" href=\"/css/bootstrap.min.css\">\n" + " <link rel=\"stylesheet\" type=\"text/css\" href=\"https://s1.gismeteo.ua/static/css/informer2/gs_informerClient.min.css\">\n" + " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" + "<script type=\"text/javascript\" src=\"http://gc.kis.scr.kaspersky-labs.com/6533F8E7-1BF0-874B-8F28-D3F17F7C86D4/main.js\" charset=\"UTF-8\"></script></head>\n" + "<body>\n" + "<div class=\"container wrapper table page\">\n" + " <div class=\"row cell\" style=\"margin-top:10px\">\n" + " <div class=\"col-md-12 places\">\n" + " <div class=\"row\">\n" + " <a href=\"/\" class=\"col-md-3 col-xs-12\">Выбор станции</a>\n" + " <a href=\"/prague\" class=\"col-md-3 col-xs-12\">Прага-Чехия</a>\n" + " <a href=\"/sheremetevo\" class=\"col-md-3 col-xs-12\">Москва-Шереметьево</a>\n" + " <a href=\"/sokolniki\" class=\"active col-md-3 col-xs-12\">Москва-Сокольники</a>\n" + " </div>\n" + " </div>\n" + " <div class=\"col-md-12 header-container\">\n" + " <div class=\"col-md-4 col-lg-3\">\n" + " <a href=\"/\"><img class=\"logo\" src=\"/images/Logo-sokolniki.png\" alt=\"Текущая погода в Сокольниках, Москва.\"></a> </div>\n" + " <div class=\"col-md-8 col-lg-9\">\n" + " <div class=\"row\">\n" + " <ul>\n" + " <li class=\"active\"><a href=\"/sokolniki\">Текущие данные</a></li>\n" + " <li class=\"\"><a href=\"/sokolniki/day.php\">Данные за сутки</a></li>\n" + " <li class=\"\"><a href=\"/sokolniki/week.php\">Данные за неделю</a></li>\n" + " <li class=\"\"><a href=\"/sokolniki/year.php\">Данные за год</a></li>\n" + " <li class=\"\"><a href=\"/sokolniki/last.php\">Архивы прошлых лет</a></li>\n" + " </ul>\n" + " <div class=\"clear\"></div>\n" + " <div class=\"col-md-12 descript-station\">\n" + " Данные получены с помощью метеостанций DAVIS Vantage Pro2. </div>\n" + " </div>\n" + " </div>\n" + " </div><div class=\"col-md-12\">\n" + " <div class=\"col-md-6\"><p style=\"text-align: right; font-weight: bold;\">Восход солнца: 8:53</p></div>\n" + " <div class=\"col-md-6\"><p style=\"text-align: left; font-weight: bold;\">Заход солнца: 15:59</p></div>\n" + " <p class=\"last-measure\" style=\"font-style: italic;\">Время последнего измерения: 15.12.16 0:13</p>\n" + " </div>\n" + " <div class=\"col-md-12\">\n" + " <table class=\"table table-bordered table-hover meteo-table\">\n" + " <tbody>\n" + " <tr>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">Температура</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">Temperature</p></td>\n" + " <td><b>-7.8 °C</b></td>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">Точка росы</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">Due point</p></td>\n" + " <td><b>-10.0 °C</b></td>\n" + " </tr>\n" + " <tr>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">Влажность</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">Humidity</p></td>\n" + " <td><b>84% </b></td>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">Температура комфорта</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">Comfort temperature</p></td>\n" + " <td><b>-9.1 °C</b></td>\n" + " </tr>\n" + " <tr>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">Ветер</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">Wind</p></td>\n" + " <td><b>E в 0.4 m/s</b></td>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">THW индекс</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">THW index</p></td>\n" + " <td><b>-9.2 °C</b></td>\n" + " </tr>\n" + " <tr>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">Давление</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">Air pressure</p></td>\n" + " <td><b>760.3 mm & Rising Rapidly</b></td>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">Индекс тепла</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">Heat index</p></td>\n" + " <td><b>-7.9 °C</b></td>\n" + " </tr>\n" + " <tr>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">Осадки сегодня</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">Rainfall today</p></td>\n" + " <td><b>0.0 mm</b></td>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">Последние осадки</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">Last rainfall</p></td>\n" + " <td><b>1.2 mm</b></td>\n" + " </tr>\n" + " <tr>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">Осадки в месяце</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">Rainfall this month</p></td>\n" + " <td><b>5.8 mm</b></td>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">Годовые осадки</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">Rainfall this year</p></td>\n" + " <td><b>355.8 mm</b></td>\n" + " </tr>\n" + " <tr>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">Скорость текущих осадков</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">Speed of the current rainfall</p></td>\n" + " <td><b>0.0 mm/hr</b></td>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">Солнечное излучение</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">Solar radiation</p></td>\n" + " <td><b>0 W/m?</b></td>\n" + " </tr>\n" + " <tr>\n" + " <td><p style=\"font-weight: bold; font-style: italic;\">УФ индекс</p>\n" + " <p style=\"font-weight: bold;font-style: italic;color: #9A9A9A;\">UV index</p></td>\n" + " <td><b>0.0 index</b></td>\n" + " <td></td>\n" + " <td></td>\n" + " </tr>\n" + " </tbody>\n" + " </table>\n" + " </div>\n" + " <div class=\"btns-weather\">\n" + " <a href='dataNOAA/downld02.txt' class=\"grafic-btn\">Табличные данные<br>за два дня</a>\n" + " <a href='dataNOAA/NOAAMO.TXT' class=\"grafic-btn\">Отчёт N0AA<br>за текущий месяц</a>\n" + " <a href=\"day.php\" class=\"grafic-btn\">Посмотреть <br> графики</a>\n" + " <a href='dataNOAA/NOAAPRMO.TXT' class=\"grafic-btn\">Отчёт N0AA<br>за прошлый месяц</a>\n" + " <a href='dataNOAA/downld08.txt' class=\"grafic-btn\">Табличные данные<br>за неделю</a>\n" + " </div>\n" + " <div class=\"col-md-12 footer\" style=\"padding-top: 20px;\">\n" + " <div class=\"row\">\n" + " <div class=\"col-md-12 col-sm-12 i-home\">\n" + " <div class=\"col-md-3 col-sm-3 informer\">\n" + " <div class=\"row\" style=\"margin:5px\">\n" + "<!-- Gismeteo informer START -->\n" + "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://bst1.gismeteo.ru/assets/flat-ui/legacy/css/informer.min.css\">\n" + "<div id=\"gsInformerID-PEq6S8DHuRG6jf\" class=\"gsInformer\" style=\"width:239px;height:103px\">\n" + " <div class=\"gsIContent\">\n" + " <div id=\"cityLink\">\n" + " <a href=\"https://www.gismeteo.ru/city/daily/4368/\" target=\"_blank\">Погода в Москве</a>\n" + " </div>\n" + " <div class=\"gsLinks\">\n" + " <table>\n" + " <tr>\n" + " <td>\n" + " <div class=\"leftCol\">\n" + " <a href=\"https://www.gismeteo.ru/\" target=\"_blank\">\n" + " <img alt=\"Gismeteo\" title=\"Gismeteo\" src=\"https://bst1.gismeteo.ru/assets/flat-ui/img/logo-mini2.png\" align=\"middle\" border=\"0\" />\n" + " <span>Gismeteo</span>\n" + " </a>\n" + " </div>\n" + " <div class=\"rightCol\">\n" + " <a href=\"https://www.gismeteo.ru/city/weekly/4368/\" target=\"_blank\">Прогноз на 2 недели</a>\n" + " </div>\n" + " </td>\n" + " </tr>\n" + " </table>\n" + " </div>\n" + " </div>\n" + "</div>\n" + "<script async src=\"https://www.gismeteo.ru/api/informer/getinformer/?hash=PEq6S8DHuRG6jf\" type=\"text/javascript\"></script>\n" + "<!-- Gismeteo informer END -->\n" + " </div>\n" + " </div>\n" + " <div class=\"col-md-9 col-sm-9\">\n\n" + "<div class=\"row\" style=\"background: #337AB7; height: 97px;\"><div style=\"border-radius: 0 0 0 25px;background: #FFFFFF;height: 55px;\"></div><h4>Сайт выполнен для <a href=\"http://aragonia.com\" style=\"color:#ccc\">Aragonia Group</a></h4></div>\n" + " </div>\n" + " </div>\n" + " </div>\n" + " </div>\n" + " </div>\n" + "<div style=\"text-align:center\">\n" + "<div style=\"display:none\">\n" + "<!-- SpyLOG f:0211 -->\n" + "<script language=\"javascript\"><!--\n" + "Mu=\"u6009.69.spylog.com\";Md=document;Mnv=navigator;Mp=0;\n" + "Md.cookie=\"b=b\";Mc=0;if(Md.cookie)Mc=1;Mrn=Math.random();\n" + "Mn=(Mnv.appName.substring(0,2)==\"Mi\")?0:1;Mt=(new Date()).getTimezoneOffset();\n" + "Mz=\"p=\"+Mp+\"&rn=\"+Mrn+\"&c=\"+Mc+\"&t=\"+Mt;\n" + "if(self!=top){Mfr=1;}else{Mfr=0;}Msl=\"1.0\";\n" + "//--></script><script language=\"javascript1.1\"><!--\n" + "Mpl=\"\";Msl=\"1.1\";Mj = (Mnv.javaEnabled()?\"Y\":\"N\");Mz+='&j='+Mj;\n" + "//--></script><script language=\"javascript1.2\"><!--\n" + "Msl=\"1.2\";Ms=screen;Mpx=(Mn==0)?Ms.colorDepth:Ms.pixelDepth;\n" + "Mz+=\"&wh=\"+Ms.width+'x'+Ms.height+\"&px=\"+Mpx;\n" + "//--></script><script language=\"javascript1.3\"><!--\n" + "Msl=\"1.3\";//--></script><script language=\"javascript\"><!--\n" + "My=\"\";My+=\"<a href='http://\"+Mu+\"/cnt?cid=600969&f=3&p=\"+Mp+\"&rn=\"+Mrn+\"' target='_blank'>\";\n" + "My+=\"<img src='http://\"+Mu+\"/cnt?cid=600969&\"+Mz+\"&sl=\"+Msl+\"&r=\"+escape(Md.referrer)+\"&fr=\"+Mfr+\"&pg=\"+escape(window.location.href);\n" + "My+=\"' border=0 width=88 height=31 alt='SpyLOG'>\";\n" + "My+=\"</a>\";Md.write(My);//--></script><noscript>\n" + "<a href=\"http://u6009.69.spylog.com/cnt?cid=600969&f=3&p=0\" target=\"_blank\">\n" + "<img src=\"http://u6009.69.spylog.com/cnt?cid=600969&p=0\" alt='SpyLOG' border='0' width=88 height=31 >\n" + "</a></noscript>\n" + "<!-- SpyLOG -->\n" + "</div>\n\n" + "<!-- HotLog -->\n" + "<span id=\"hotlog_counter\"></span>\n" + "<span id=\"hotlog_dyn\"></span>\n" + "<script type=\"text/javascript\">\n" + "var hot_s = document.createElement('script');\n" + "hot_s.type = 'text/javascript'; hot_s.async = true;\n" + "hot_s.src = 'http://js.hotlog.ru/dcounter/427664.js';\n" + "hot_d = document.getElementById('hotlog_dyn');\n" + "hot_d.appendChild(hot_s);\n" + "</script>\n" + "<noscript>\n" + "<a href=\"http://click.hotlog.ru/?427664\" target=\"_blank\"><img\n" + "src=\"http://hit23.hotlog.ru/cgi-bin/hotlog/count?s=427664&amp;im=303\" border=\"0\"\n" + "alt=\"HotLog\"></a>\n" + "</noscript>\n" + "<!-- /HotLog -->\n\n" + "<!-- Yandex.Metrika informer -->\n" + "<a href=\"https://metrika.yandex.ru/stat/?id=36081945&amp;from=informer\"\n" + "target=\"_blank\" rel=\"nofollow\"><img src=\"https://informer.yandex.ru/informer/36081945/3_1_ECECECFF_CCCCCCFF_0_uniques\"\n" + "style=\"width:88px; height:31px; border:0;\" alt=\"Яндекс.Метрика\" title=\"Яндекс.Метрика: данные за сегодня (просмотры, визиты и уникальные посетители)\" onclick=\"try{Ya.Metrika.informer({i:this,id:36081945,lang:'ru'});return false}catch(e){}\" /></a>\n" + "<!-- /Yandex.Metrika informer -->\n\n" + "<!-- Yandex.Metrika counter -->\n" + "<script type=\"text/javascript\">\n" + " (function (d, w, c) {\n" + " (w[c] = w[c] || []).push(function() {\n" + " try {\n" + " w.yaCounter36081945 = new Ya.Metrika({\n" + " id:36081945,\n" + " clickmap:true,\n" + " trackLinks:true,\n" + " accurateTrackBounce:true\n" + " });\n" + " } catch(e) { }\n" + " });\n\n" + " var n = d.getElementsByTagName(\"script\")[0],\n" + " s = d.createElement(\"script\"),\n" + " f = function () { n.parentNode.insertBefore(s, n); };\n" + " s.type = \"text/javascript\";\n" + " s.async = true;\n" + " s.src = \"https://mc.yandex.ru/metrika/watch.js\";\n\n" + " if (w.opera == \"[object Opera]\") {\n" + " d.addEventListener(\"DOMContentLoaded\", f, false);\n" + " } else { f(); }\n" + " })(document, window, \"yandex_metrika_callbacks\");\n" + "</script>\n" + "<noscript><div><img src=\"https://mc.yandex.ru/watch/36081945\" style=\"position:absolute; left:-9999px;\" alt=\"\" /></div></noscript>\n" + "<!-- /Yandex.Metrika counter -->\n" + "</div>\n" + "</div>\n" + "<script src=\"/js/jquery-2.1.1.js\"></script>\n" + "<script src=\"/js/bootstrap.min.js\"></script>\n" + "<script src=\"http://code.jquery.com/jquery-1.10.2.min.js\"></script>\n" + "<script src=\"http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js\"></script>\n" + "<script src=\"//cdn.jsdelivr.net/stickynavbar.js/1.3.2/jquery.stickyNavbar.min.js\"></script>\n" + "</body>\n" + "</html>"; 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