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

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

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions