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

/
/
gu

Test String

Code Generator

Generated Code

$re = '/<a aria-describedby=(?s).+?data-control-name="topcard_headquarters"\h+href="(?-s)(.+?)\h+rel=/u'; $str = '<div class="top-card"> <div id="ember862" class="entity-card nav company ember-view"> <div class="nav-container"> <div id="ember863" class="avatar inline-table ember-view"><img src="https://media.licdn.com/dms/image/C560BAQHXIWxrkUKdKg/company-logo_100_100/0?e=1579737600&amp;v=beta&amp;t=UBw6s13aoyScxYiCc41zzf6-xr0TNukCph8sSDpuEOE" class="entity-image entity-size-2 company " alt="Cutter &amp;amp; Buck’s logo"> </div> <div class="content-container"> <h1 id="ember864" class="flex align-items-center title ember-view"> Cutter &amp; Buck </h1> </div> <div class="right actions-container"> <artdeco-dropdown id="ember866" class="save-to-list-dropdown ember-view"><artdeco-dropdown-trigger aria-expanded="false" role="button" placement="bottom" id="ember867" class="save-to-list-dropdown__trigger button-secondary-small m-type--message ember-view" tabindex="0"> Save <!----></artdeco-dropdown-trigger><artdeco-dropdown-content arrow-dir="right" justification="left" placement="bottom" data-dropdown="" tabindex="-1" aria-hidden="true" id="ember868" class="save-to-list-dropdown__content-container artdeco-dropdown-with-arrow ember-view"> <!----> </artdeco-dropdown-content></artdeco-dropdown> </div> </div> </div> <div class="entity-card company banner"> <div id="ember869" class="avatar ember-view"><img src="https://media.licdn.com/dms/image/C560BAQHXIWxrkUKdKg/company-logo_100_100/0?e=1579737600&amp;v=beta&amp;t=UBw6s13aoyScxYiCc41zzf6-xr0TNukCph8sSDpuEOE" class="entity-image entity-size-6 company " alt="Cutter &amp;amp; Buck’s logo"> </div> <div class="content-container"> <div class="flex align-items-center mb1"> <h1 class="title inline-block"> Cutter &amp; Buck </h1> <!----> </div> <div class="modal-description-wrapper"> <h2 class="subtitle" role="link" data-control-name="topcard_companyDescription"> <div id="ember870" class="ember-view">Cutter &amp; Buck Inc. was found…<button class="button--unstyled link-without-visited-state inline-block font-size-inherit topcard-see-more-link" type="button">See all</button></div> </h2> </div> <p class="muted-copy Sans-14px-black-60%"> Apparel &amp; Fashion · United States · 201-500 employees <!----> </p> <span class="cta-link"> <span class="facepile-container"> <img src="https://media.licdn.com/dms/image/C4D03AQHeGZtGLzfKuA/profile-displayphoto-shrink_800_800/0?e=1577318400&amp;v=beta&amp;t=WtB92LCoZaMWXLBjmAMGLg86s9U0_9j_brVtVK8PO58" class="ghost-person circle-facepile" alt=""> <img src="https://media.licdn.com/dms/image/C4D03AQEhREY07Z_MHg/profile-displayphoto-shrink_800_800/0?e=1577318400&amp;v=beta&amp;t=2iZZguioIkpBzfsM29vbtGY_uBoqoEYEOekQR1JGDZE" class="ghost-person circle-facepile" alt=""> <img src="https://media.licdn.com/dms/image/C5603AQE0mzb2-gU5Kw/profile-displayphoto-shrink_800_800/0?e=1577318400&amp;v=beta&amp;t=HRF5YwFFHSI1NjhU4-SbAWYtyT_9pGf9Zd6JLiGRiA8" class="ghost-person circle-facepile" alt=""> <!----><!----><!----><!----><!----> </span> <a data-control-name="topcard_employees" href="/sales/search/people/list/employees-for-account/14178" id="ember879" class="ember-view"> 298 employees </a> <div class="mh2">|</div> <a data-control-name="num_decision-makers" href="/sales/search/people/list/employees-for-account/14178?seniority=6%2C7%2C8" id="ember880" class="ember-view"> 30 decision makers </a> </span> <div class="mt4"> <ul class="flex flex-wrap list-style-none"> <!----> <li id="ember881" class="inline-flex mt2 ml1 pb1 ember-view"> <button class="topcard__add-button t-14 t-bold t-black--light button--unstyled" data-control-name="topcard_addTag"> <li-icon aria-hidden="true" type="plus-icon" class="vertical-align-text-bottom" size="small"><svg viewBox="0 0 24 24" width="24px" height="24px" x="0" y="0" preserveAspectRatio="xMinYMin meet" class="artdeco-icon" focusable="false"><path d="M14,9H9v5H7V9H2V7H7V2H9V7h5V9Z" class="small-icon" style="fill-opacity: 1"></path></svg></li-icon> Add Tag </button> <!----> </li> </ul> <div id="ember882" class="ember-view"><!----></div> </div> </div> <div class="right actions-container mt1"> <div class="company-topcard-actions flex align-items-center"> <artdeco-dropdown id="ember884" class="save-to-list-dropdown ember-view"><artdeco-dropdown-trigger aria-expanded="false" role="button" placement="bottom" id="ember885" class="save-to-list-dropdown__trigger button-primary-large ember-view" tabindex="0"> Save <!----></artdeco-dropdown-trigger><artdeco-dropdown-content arrow-dir="right" justification="left" placement="bottom" data-dropdown="" tabindex="-1" aria-hidden="true" id="ember886" class="save-to-list-dropdown__content-container artdeco-dropdown-with-arrow ember-view"> <!----> </artdeco-dropdown-content></artdeco-dropdown> <artdeco-dropdown id="ember887" class="ember-view"><artdeco-dropdown-trigger aria-expanded="false" role="button" placement="bottom" id="ember888" class="button-round-tertiary-medium-muted block ml1 ember-view" tabindex="0"> <li-icon type="ellipsis-horizontal-icon" role="img" aria-label="More actions"><svg viewBox="0 0 24 24" width="24px" height="24px" x="0" y="0" preserveAspectRatio="xMinYMin meet" class="artdeco-icon" focusable="false"><path d="M2,10H6v4H2V10Zm8,4h4V10H10v4Zm8-4v4h4V10H18Z" class="large-icon" style="fill: currentColor"></path></svg></li-icon> <!----></artdeco-dropdown-trigger><artdeco-dropdown-content arrow-dir="right" justification="right" placement="bottom" data-dropdown="" tabindex="-1" aria-hidden="true" id="ember889" class="company-topcard-actions__overflow-dropdown artdeco-dropdown-with-arrow ember-view"><!----></artdeco-dropdown-content></artdeco-dropdown> </div> <div class="meta-links"> <div class="topcard-hovercard-meta-links"> <artdeco-hoverable-trigger tabindex="-1" id="ember890" class="ember-view"> <a aria-describedby="artdeco-hoverable-artdeco-gen-63" aria-label="Go to website (new window)" class="inverse-link-on-a-light-background link-without-visited-state meta-link" data-control-name="topcard_website" href="http://www.cutterbuck.com" rel="noopener noreferrer" target="_blank"> <li-icon aria-hidden="true" type="link-icon" size="small"><svg viewBox="0 0 24 24" width="24px" height="24px" x="0" y="0" preserveAspectRatio="xMinYMin meet" class="artdeco-icon" focusable="false"><path d="M11,2a3,3,0,0,0-2.1.87L6.87,4.94a2.93,2.93,0,0,0-.72,1.21,2.93,2.93,0,0,0-1.21.72L2.87,8.94a3,3,0,1,0,4.19,4.19l2.07-2.07a2.93,2.93,0,0,0,.72-1.21,2.93,2.93,0,0,0,1.21-.72l2.07-2.07A3,3,0,0,0,11,2ZM5.83,11.89a1.22,1.22,0,0,1-1.72-1.72L6.17,8.11l0,0A3,3,0,0,0,7.91,9.8l0,0Zm6.07-6.07L9.83,7.89l0,0A3,3,0,0,0,8.09,6.2l0,0,2.07-2.07A1.22,1.22,0,0,1,11.89,5.83Z" class="small-icon" style="fill-opacity: 1"></path></svg></li-icon>Website </a> <div id="artdeco-gen-63" class="ember-view" style="display: none;"><div id="ember892" class="ember-view"></div></div></artdeco-hoverable-trigger> </div> <div class="topcard-hovercard-meta-links"> <artdeco-hoverable-trigger tabindex="-1" id="ember893" class="ember-view"> <a aria-describedby="artdeco-hoverable-artdeco-gen-64" aria-label="Go to address (new window)" class="inverse-link-on-a-light-background link-without-visited-state meta-link" data-control-name="topcard_headquarters" href="https://www.google.com/maps/place/101+Elliott+AVE+W+Suite+100+Seattle+WA+98119+United+States" rel="noopener noreferrer" target="_blank"> <li-icon aria-hidden="true" type="map-marker-icon" size="small"><svg viewBox="0 0 24 24" width="24px" height="24px" x="0" y="0" preserveAspectRatio="xMinYMin meet" class="artdeco-icon" focusable="false"><path d="M8,4a2,2,0,1,0,2,2A2,2,0,0,0,8,4ZM8,7.13A1.13,1.13,0,1,1,9.13,6,1.13,1.13,0,0,1,8,7.13ZM8,1A5,5,0,0,0,3,6a5.37,5.37,0,0,0,.41,2S5.91,13,7.22,15.52A0.86,0.86,0,0,0,8,16H8a0.86,0.86,0,0,0,.78-0.48C10.09,13,12.59,8,12.59,8A5.37,5.37,0,0,0,13,6,5,5,0,0,0,8,1Zm2.88,6.24L8,12.92,5.12,7.24A3.49,3.49,0,0,1,4.88,6a3.13,3.13,0,0,1,6.25,0A3.49,3.49,0,0,1,10.88,7.24Z" class="small-icon" style="fill-opacity: 1"></path></svg></li-icon>Headquarters </a> <div id="artdeco-gen-64" class="ember-view" style="display: none;"><div id="ember895" class="ember-view"></div></div></artdeco-hoverable-trigger> </div> </div> <button class="add-note topcard__add-button t-14 t-bold t-black--light" data-control-name="topcard_addNote" data-ember-action="" data-ember-action-896="896"> <li-icon aria-hidden="true" type="sticky-note-icon" size="small"><svg viewBox="0 0 24 24" width="24px" height="24px" x="0" y="0" preserveAspectRatio="xMinYMin meet" class="artdeco-icon" focusable="false"><path d="M2,3V13a1,1,0,0,0,1,1h7.13L14,10.1V3a1,1,0,0,0-1-1H3A1,1,0,0,0,2,3ZM4,4h8V9H9v3H4V4Z" class="small-icon" style="fill-opacity: 1"></path></svg></li-icon> Add Note </button> <!----> </div> </div> </div>'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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