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

/
/
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/(.*-.*?<br>.*)/m'; $str = '<div class="post hentry" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting"> <meta content="http://2.bp.blogspot.com/-Xr8J0BgpT-Y/U0r8PrjYqkI/AAAAAAAAAZs/HqpN2aM1dMM/s1600/IMG_4494.jpg" itemprop="image_url"> <meta content="4117404407927449930" itemprop="blogId"> <meta content="4496590050094219863" itemprop="postId"> <a name="4496590050094219863"></a> <h3 class="post-title entry-title" itemprop="name"> <a href="http://kaszomania.blogspot.com/2014/04/roso-z-kasza-jaglana.html">Rosół z kaszą jaglaną</a> </h3> <div style="float: none;"> <iframe allowtransparency="true" frameborder="0" scrolling="no" src="http://www.facebook.com/plugins/like.php?href=http://kaszomania.blogspot.com/2014/04/roso-z-kasza-jaglana.html&amp;send=false&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=35" style="border:none; overflow:hidden; width:450px; height:35px;"></iframe> </div> <div class="post-header"> <div class="post-header-line-1"></div> </div> <div class="post-body entry-content" id="post-body-4496590050094219863" itemprop="description articleBody"> <div style="text-align: justify;"> Jak mawia Ferdek Kiepski - <i>bez mięsa człowiek daleko nie zajedzie...</i> Oczywiście dzisiejszy wpis nie będzie tematem rozważań na temat prawdziwości lub też nie tego stwierdzenia. Nie zmienia to faktu, że każdy czasem lubi zjeść rosół z kury. :) Rosół jest bombą witaminową doskonałą na przeziębienie, a dodatek w postaci kaszy jaglanej nie tylko urozmaici potrawę, ale także podniesie jej walory zdrowotne. Jak dla mnie ziemniaki oraz wszelkie makarony wymiękają przy kaszy jaglanej. ;)</div> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="http://2.bp.blogspot.com/-Xr8J0BgpT-Y/U0r8PrjYqkI/AAAAAAAAAZs/HqpN2aM1dMM/s1600/IMG_4494.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Rosół z kaszą jaglaną" border="0" src="http://2.bp.blogspot.com/-Xr8J0BgpT-Y/U0r8PrjYqkI/AAAAAAAAAZs/HqpN2aM1dMM/s1600/IMG_4494.jpg" height="358" title="Rosół z kaszą jaglaną" width="640"></a></div> <br> Składniki:<br> - kasza jaglana <br> - 4-5 udek z kurczaka<br> - włoszczyzna: korzeń pietruszki, marchewka, seler, por (ja kupuję gotową w biedronce)<br> - cebula<br> - natka pietruszki<br> - sól<br> - pieprz<br> - ziele angielskie<br> - liść laurowy<br> - ok. 2 litry wody<br> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="http://1.bp.blogspot.com/-MD-NFwHYAVE/U0r8OjOlbEI/AAAAAAAAAZg/sG6n3tuxN2o/s1600/IMG_4458.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Rosół z kaszą jaglaną" border="0" src="http://1.bp.blogspot.com/-MD-NFwHYAVE/U0r8OjOlbEI/AAAAAAAAAZg/sG6n3tuxN2o/s1600/IMG_4458.jpg" height="358" title="Rosół z kaszą jaglaną" width="640"></a></div> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="http://2.bp.blogspot.com/-pq7Nvs_5I7Y/U0r8O8pfgLI/AAAAAAAAAZo/qfJja3ewbcg/s1600/IMG_4491.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Rosół z kaszą jaglaną" border="0" src="http://2.bp.blogspot.com/-pq7Nvs_5I7Y/U0r8O8pfgLI/AAAAAAAAAZo/qfJja3ewbcg/s1600/IMG_4491.jpg" height="358" title="Rosół z kaszą jaglaną" width="640"></a></div> <ol style="text-align: justify;"> <li>Gotujemy kaszę jaglaną na sypko (z dodatkiem soli).</li> <li>Myjemy udka i wrzucamy do gara. Zalewamy ok 2 litrami zimnej wody i doprowadzamy do wrzenia. Gotujemy na bardzo małym ogniu. Zbieramy tzw. szumowiny.</li> <li>Kroimy warzywa. Seler w kostkę. Marchewkę, korzeń pietruszki, pora w paski. Cebulę kroimy na dwie połówki. Wszystkie warzywa wrzucamy do gara i dalej gotujemy.</li> <li>Dodajemy przyprawy - sól, pieprz, liść laurowy, ziele angielskie, natkę pietruszki w całości.</li> <li>Pozostawiamy rosół aby "pyrkał :D" się przez ok. 1,5 godziny. Jeżeli zbyt mało doprawiliście możecie w międzyczasie dodawać przyprawy i sprawdzać smak.</li> <li>Rosół jest gotowy, kiedy zacznie smakować jak rosół i kiedy warzywa będą wystarczająco miękkie. Nie wyrzucamy z rosołu żadnych warzyw. To barbarzyństwo!!!:)</li> <li>Przed podaniem, do miseczki wsypujemy kaszę jaglaną, a następnie całość zalewamy gorącym rosołem.</li> </ol> <div style="text-align: justify;"> SMACZNEGO! :) </div> <br> <div class="separator" style="clear: both; text-align: center;"> <a href="http://2.bp.blogspot.com/-Xr8J0BgpT-Y/U0r8PrjYqkI/AAAAAAAAAZ0/6KtSzSwbqYA/s1600/IMG_4494.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="Rosół z kaszą jaglaną" border="0" src="http://2.bp.blogspot.com/-Xr8J0BgpT-Y/U0r8PrjYqkI/AAAAAAAAAZ0/6KtSzSwbqYA/s1600/IMG_4494.jpg" height="358" title="Rosół z kaszą jaglaną" width="640"></a></div> <br> <br> <div style="clear: both;"></div> <div id="lws_0"><div class="linkwithin_outer" style="margin: 0; border: 0; padding: 0; clear: both; "> <div id="linkwithin_inner" class="linkwithin_inner" style=" margin: 0; border: 0; padding: 0; width: 596px; "> <div class="linkwithin_text" id="linkwithin_text_0" style=" margin: 0; border: 0; padding: 20px 0 5px; text-align: left; font-weight: bold; ">Inne dania z kaszą:</div> <div class="linkwithin_posts" id="linkwithin_posts_0" style="margin: 0; border: 0; padding: 0"> <a name="linkwithin_link_0" href="http://kaszomania.blogspot.com/2014/03/kasza-jaglana-z-warzywami-na-patelnie.html" onmousedown="this.href=\'http://widget6.linkwithin.com/redirect?url=http%3A//kaszomania.blogspot.com/2014/03/kasza-jaglana-z-warzywami-na-patelnie.html&amp;rtype=&amp;vars=%5B%22http%3A//kaszomania.blogspot.com/search/label/zupy%22%2C%202065963%2C%200%2C%20%22http%3A//kaszomania.blogspot.com/2014/04/roso-z-kasza-jaglana.html%22%2C%20383537545%2C%200%2C%20383537563%5D&amp;ts=\' + (new Date()).getTime(); return true;" style=" display: block; float: left; border-bottom: none; margin: 0; padding: 6px; text-decoration: none; text-align: left; cursor: pointer; " onmouseover="this.style.backgroundColor=\'#dde\'" onmouseout="this.style.backgroundColor=\'\'"> <div style="width: 106px; height: 165px; margin: 0; border: 0; padding: 0"> <div class="linkwithin_img_0" style=" margin: 0; border: 1px solid #ddd; padding: 2px; width: auto; height: auto; "> <div style="background: url(http://images3.linkwithin.com/images/383537563.jpg) no-repeat; width: 100px; height: 100px; margin: 0; border: 0; padding: 0"></div> </div> <div class="linkwithin_title linkwithin_title_0" style="margin: 3px 0px 0px; border: 0px; padding: 0px; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-family: arial; color: rgb(102, 102, 102);"> Kasza jaglana z warzywami na patelnię </div> </div> </a> <a name="linkwithin_link_0" href="http://kaszomania.blogspot.com/2014/01/saatka-z-kaszy-jaglanej-i-ososia.html" onmousedown="this.href=\'http://widget6.linkwithin.com/redirect?url=http%3A//kaszomania.blogspot.com/2014/01/saatka-z-kaszy-jaglanej-i-ososia.html&amp;rtype=&amp;vars=%5B%22http%3A//kaszomania.blogspot.com/search/label/zupy%22%2C%202065963%2C%200%2C%20%22http%3A//kaszomania.blogspot.com/2014/04/roso-z-kasza-jaglana.html%22%2C%20383537545%2C%201%2C%20352602665%5D&amp;ts=\' + (new Date()).getTime(); return true;" style=" display: block; float: left; border-left: 1px solid #ddd; border-bottom: none; margin: 0; padding: 6px; text-decoration: none; text-align: left; cursor: pointer; " onmouseover="this.style.backgroundColor=\'#dde\'" onmouseout="this.style.backgroundColor=\'\'"> <div style="width: 106px; height: 165px; margin: 0; border: 0; padding: 0"> <div class="linkwithin_img_0" style=" margin: 0; border: 1px solid #ddd; padding: 2px; width: auto; height: auto; "> <div style="background: url(http://images3.linkwithin.com/images/352602665.jpg) no-repeat; width: 100px; height: 100px; margin: 0; border: 0; padding: 0"></div> </div> <div class="linkwithin_title linkwithin_title_0" style="margin: 3px 0px 0px; border: 0px; padding: 0px; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-family: arial; color: rgb(102, 102, 102);"> Sałatka z kaszy jaglanej i łososia </div> </div> </a> <a name="linkwithin_link_0" href="http://kaszomania.blogspot.com/2014/03/kasza-jaglana-z-bananowym-gulaszem.html" onmousedown="this.href=\'http://widget6.linkwithin.com/redirect?url=http%3A//kaszomania.blogspot.com/2014/03/kasza-jaglana-z-bananowym-gulaszem.html&amp;rtype=&amp;vars=%5B%22http%3A//kaszomania.blogspot.com/search/label/zupy%22%2C%202065963%2C%200%2C%20%22http%3A//kaszomania.blogspot.com/2014/04/roso-z-kasza-jaglana.html%22%2C%20383537545%2C%202%2C%20383537567%5D&amp;ts=\' + (new Date()).getTime(); return true;" style=" display: block; float: left; border-left: 1px solid #ddd; border-bottom: none; margin: 0; padding: 6px; text-decoration: none; text-align: left; cursor: pointer; " onmouseover="this.style.backgroundColor=\'#dde\'" onmouseout="this.style.backgroundColor=\'\'"> <div style="width: 106px; height: 165px; margin: 0; border: 0; padding: 0"> <div class="linkwithin_img_0" style=" margin: 0; border: 1px solid #ddd; padding: 2px; width: auto; height: auto; "> <div style="background: url(http://images3.linkwithin.com/images/383537567.jpg) no-repeat; width: 100px; height: 100px; margin: 0; border: 0; padding: 0"></div> </div> <div class="linkwithin_title linkwithin_title_0" style="margin: 3px 0px 0px; border: 0px; padding: 0px; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-family: arial; color: rgb(102, 102, 102);"> Kasza jaglana z bananowym gulaszem </div> </div> </a> <a name="linkwithin_link_0" href="http://kaszomania.blogspot.com/2014/02/zupa-krem-z-kaszy-jaglanej-i-szpinaku.html" onmousedown="this.href=\'http://widget6.linkwithin.com/redirect?url=http%3A//kaszomania.blogspot.com/2014/02/zupa-krem-z-kaszy-jaglanej-i-szpinaku.html&amp;rtype=&amp;vars=%5B%22http%3A//kaszomania.blogspot.com/search/label/zupy%22%2C%202065963%2C%200%2C%20%22http%3A//kaszomania.blogspot.com/2014/04/roso-z-kasza-jaglana.html%22%2C%20383537545%2C%203%2C%20383537577%5D&amp;ts=\' + (new Date()).getTime(); return true;" style=" display: block; float: left; border-left: 1px solid #ddd; border-bottom: none; margin: 0; padding: 6px; text-decoration: none; text-align: left; cursor: pointer; " onmouseover="this.style.backgroundColor=\'#dde\'" onmouseout="this.style.backgroundColor=\'\'"> <div style="width: 106px; height: 165px; margin: 0; border: 0; padding: 0"> <div class="linkwithin_img_0" style=" margin: 0; border: 1px solid #ddd; padding: 2px; width: auto; height: auto; "> <div style="background: url(http://images3.linkwithin.com/images/383537577.jpg) no-repeat; width: 100px; height: 100px; margin: 0; border: 0; padding: 0"></div> </div> <div class="linkwithin_title linkwithin_title_0" style="margin: 3px 0px 0px; border: 0px; padding: 0px; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-family: arial; color: rgb(102, 102, 102);"> Zupa krem z kaszy jaglanej i szpinaku </div> </div> </a> <a name="linkwithin_link_0" href="http://kaszomania.blogspot.com/2014/01/zupa-krem-z-kukurydzy-i-kaszy-jaglanej.html" id="linkwithin_link_last" onmousedown="this.href=\'http://widget6.linkwithin.com/redirect?url=http%3A//kaszomania.blogspot.com/2014/01/zupa-krem-z-kukurydzy-i-kaszy-jaglanej.html&amp;rtype=&amp;vars=%5B%22http%3A//kaszomania.blogspot.com/search/label/zupy%22%2C%202065963%2C%200%2C%20%22http%3A//kaszomania.blogspot.com/2014/04/roso-z-kasza-jaglana.html%22%2C%20383537545%2C%204%2C%20383537619%5D&amp;ts=\' + (new Date()).getTime(); return true;" style=" display: block; float: left; border-left: 1px solid #ddd; border-bottom: none; margin: 0; padding: 6px; text-decoration: none; text-align: left; cursor: pointer; " onmouseover="this.style.backgroundColor=\'#dde\'" onmouseout="this.style.backgroundColor=\'\'"> <div style="width: 106px; height: 165px; margin: 0; border: 0; padding: 0"> <div class="linkwithin_img_0" style=" margin: 0; border: 1px solid #ddd; padding: 2px; width: auto; height: auto; "> <div style="background: url(http://images3.linkwithin.com/images/383537619.jpg) no-repeat; width: 100px; height: 100px; margin: 0; border: 0; padding: 0"></div> </div> <div class="linkwithin_title linkwithin_title_0" style="margin: 3px 0px 0px; border: 0px; padding: 0px; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-family: arial; color: rgb(102, 102, 102);"> Zupa krem z kukurydzy i kaszy jaglanej </div> </div> </a> </div> <div id="linkwithin_logo_0" style=" clear: both; margin: 0 0 20px 0; border: 0; padding: 5px 6px 0 0; text-align: right; "> <a id="linkwithin_logolink_0" href="http://www.linkwithin.com/learn?ref=widget" style=" font: 10px arial; color: #bbb; text-decoration: none; border-bottom: none; " onmouseover="this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'" target="_blank">Linkwithin</a> </div> </div> </div></div></div> <div class="post-footer"> <div class="post-footer-line post-footer-line-1"><span class="post-author vcard"> Autor: <span class="fn" itemprop="author" itemscope="itemscope" itemtype="http://schema.org/Person"> <meta content="http://www.blogger.com/profile/07377519070516761764" itemprop="url"> <a class="g-profile" href="http://www.blogger.com/profile/07377519070516761764" rel="author" title="author profile" data-gapiscan="true" data-onload="true" data-gapiattached="true"> <span itemprop="name">Kaszomaniak</span> </a> </span> </span> <span class="post-timestamp"> o <meta content="http://kaszomania.blogspot.com/2014/04/roso-z-kasza-jaglana.html" itemprop="url"> <a class="timestamp-link" href="http://kaszomania.blogspot.com/2014/04/roso-z-kasza-jaglana.html" rel="bookmark" title="permanent link"><abbr class="published" itemprop="datePublished" title="2014-04-14T19:00:00+02:00">19:00</abbr></a> </span> <span class="post-comment-link"> <a class="comment-link" href="http://kaszomania.blogspot.com/2014/04/roso-z-kasza-jaglana.html#comment-form" onclick=""> 2 komentarze: </a> </span> <span class="post-icons"> <span class="item-control blog-admin pid-56923570"> <a href="http://www.blogger.com/post-edit.g?blogID=4117404407927449930&amp;postID=4496590050094219863&amp;from=pencil" title="Edytuj post"> <img alt="" class="icon-action" height="18" src="http://img2.blogblog.com/img/icon18_edit_allbkg.gif" width="18"> </a> </span> </span> <div class="post-share-buttons goog-inline-block"> <a class="goog-inline-block share-button sb-email" href="http://www.blogger.com/share-post.g?blogID=4117404407927449930&amp;postID=4496590050094219863&amp;target=email" target="_blank" title="Wyślij pocztą e-mail"><span class="share-button-link-text">Wyślij pocztą e-mail</span></a><a class="goog-inline-block share-button sb-blog" href="http://www.blogger.com/share-post.g?blogID=4117404407927449930&amp;postID=4496590050094219863&amp;target=blog" onclick="window.open(this.href, &quot;_blank&quot;, &quot;height=270,width=475&quot;); return false;" target="_blank" title="Wrzuć na bloga"><span class="share-button-link-text">Wrzuć na bloga</span></a><a class="goog-inline-block share-button sb-twitter" href="http://www.blogger.com/share-post.g?blogID=4117404407927449930&amp;postID=4496590050094219863&amp;target=twitter" target="_blank" title="Udostępnij w usłudze Twitter"><span class="share-button-link-text">Udostępnij w usłudze Twitter</span></a><a class="goog-inline-block share-button sb-facebook" href="http://www.blogger.com/share-post.g?blogID=4117404407927449930&amp;postID=4496590050094219863&amp;target=facebook" onclick="window.open(this.href, &quot;_blank&quot;, &quot;height=430,width=640&quot;); return false;" target="_blank" title="Udostępnij w usłudze Facebook"><span class="share-button-link-text">Udostępnij w usłudze Facebook</span></a><a class="goog-inline-block share-button sb-pinterest" href="http://www.blogger.com/share-post.g?blogID=4117404407927449930&amp;postID=4496590050094219863&amp;target=pinterest" target="_blank" title="Udostępnij w serwisie Pinterest"><span class="share-button-link-text">Udostępnij w serwisie Pinterest</span></a><div class="goog-inline-block dummy-container"><div id="___plusone_0" style="text-indent: 0px; margin: 0px; padding: 0px; border-style: none; float: none; line-height: normal; font-size: 1px; vertical-align: baseline; display: inline-block; width: 300px; height: 20px; background: transparent;"><iframe frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" style="position: static; top: 0px; width: 300px; margin: 0px; border-style: none; left: 0px; visibility: visible; height: 20px;" tabindex="0" vspace="0" width="100%" id="I0_1411592047953" name="I0_1411592047953" src="https://apis.google.com/u/0/se/0/_/+1/fastbutton?usegapi=1&amp;source=blogger%3Ablog%3Aplusone&amp;size=medium&amp;width=300&amp;annotation=inline&amp;hl=pl&amp;origin=http%3A%2F%2Fkaszomania.blogspot.com&amp;url=http%3A%2F%2Fkaszomania.blogspot.com%2F2014%2F04%2Froso-z-kasza-jaglana.html&amp;gsrc=3p&amp;jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.pl.AJ1Kb6hzPQA.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Ft%3Dzcms%2Frs%3DAItRSTOQ2GvmXAWDDhyJad6LrCO_cwamnw#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh&amp;id=I0_1411592047953&amp;parent=http%3A%2F%2Fkaszomania.blogspot.com&amp;pfname=&amp;rpctoken=16053696" data-gapiattached="true" title="+1"></iframe></div></div> </div> </div> <div class="post-footer-line post-footer-line-2"><span class="post-labels"> Etykiety: <a href="http://kaszomania.blogspot.com/search/label/dr%C3%B3b" rel="tag">drób</a>, <a href="http://kaszomania.blogspot.com/search/label/kasza%20jaglana" rel="tag">kasza jaglana</a>, <a href="http://kaszomania.blogspot.com/search/label/marchew" rel="tag">marchew</a>, <a href="http://kaszomania.blogspot.com/search/label/pietruszka" rel="tag">pietruszka</a>, <a href="http://kaszomania.blogspot.com/search/label/warzywa" rel="tag">warzywa</a>, <a href="http://kaszomania.blogspot.com/search/label/zupy" rel="tag">zupy</a> </span> </div> <div class="post-footer-line post-footer-line-3"><span class="post-location"> </span> </div> </div> </div>'; $subst = "$1"; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$result;

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php