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

r"
"
gm

Test String

Code Generator

Generated Code

$re = '/src=\"(\S+)?\".+\s.+\s.+href=(\S+).+ember-view\">\s+(\S+)?(?:\s(\S+))\s(\S+)\s+.+\s+.+\s.+\s\S+\s.+\s.+clamp__line.+?(?=>)\W(\s+.+(?=<!)|.+(?=<\/span>))/m'; $str = '<section id="ember381" class="artdeco-card artdeco-card--with-hover ember-view"><!----> <div class="org-people-profile-card__profile-info"> <artdeco-entity-lockup stacked="center" size="5" id="ember382" class="artdeco-entity-lockup--stacked-center artdeco-entity-lockup--size-5 artdeco-entity-lockup ember-view"><artdeco-entity-lockup-image id="ember383" class="artdeco-entity-lockup__image artdeco-entity-lockup__image--type-circle ember-view" type="circle"><a data-control-name="people_profile_card_image_link" href="/in/omar-bakali-85464741/" id="ember384" class="ember-view"> <img class="lazy-image loaded" alt="Omar’s profile picture" src="https://media.licdn.com/dms/image/C4D03AQFLLRD0oaAAPw/profile-displayphoto-shrink_100_100/0?e=1565827200&amp;v=beta&amp;t=1FUl_3ALdjwdoHj0Oqq1lt5Es-0SPekm1zt-G_iVH3g" width="72" height="72"> </a> </artdeco-entity-lockup-image><artdeco-entity-lockup-content id="ember385" class="artdeco-entity-lockup__content ember-view"><artdeco-entity-lockup-title id="ember386" class="artdeco-entity-lockup__title ember-view"><a data-control-name="people_profile_card_name_link" href="/in/omar-bakali-85464741/" id="ember387" class="link-without-visited-state ember-view"> <div id="ember389" class="org-people-profile-card__profile-title t-black lt-line-clamp lt-line-clamp--single-line ember-view"> Omar Bakali <!----></div> </a> </artdeco-entity-lockup-title> <artdeco-entity-lockup-badge id="ember390" class="artdeco-entity-lockup__badge ember-view"> <span class="artdeco-entity-lockup__degree ">·&nbsp;1st</span> <!----><!----></artdeco-entity-lockup-badge> <artdeco-entity-lockup-subtitle id="ember391" class="artdeco-entity-lockup__subtitle ember-view"> <div class="t-14 t-black--light t-normal"> <div id="ember393" class="ember-view"> <span class="lt-line-clamp__line lt-line-clamp__line--last"> Founder &amp; CEO @ Ayni Widny<!----></span> <!----><span class="lt-line-clamp__ellipsis lt-line-clamp__ellipsis--dummy">...</span></div> </div> </artdeco-entity-lockup-subtitle><artdeco-entity-lockup-caption id="ember394" class="artdeco-entity-lockup__caption ember-view"> <div class="truncate"> ’14 Management </div> </artdeco-entity-lockup-caption></artdeco-entity-lockup-content> </artdeco-entity-lockup> <span> <img class="lazy-image round-image EntityPhoto-circle-1 v-align-middle loaded" alt="lionel’s profile picture" src="https://media.licdn.com/dms/image/C4E03AQH3TWM5bEiO1g/profile-displayphoto-shrink_100_100/0?e=1565827200&amp;v=beta&amp;t=r1QXqaWKGQI3PAbSYD2EKibJLV2LyDNrWLJhiuUPGx8" width="72" height="72"> <span class="t-12 t-black t-bold"> 26 shared connections </span> </span> </div> <footer class="artdeco-card__actions"> <a data-control-name="people_profile_card_message_link" target="_blank" href="/messaging/compose/?connId=ACoAAAjQ0AABtNb896iwtKva5joQFIxDhxGBfAQ" id="ember395" class="artdeco-button artdeco-button--tertiary artdeco-button--fluid artdeco-button--3 ember-view"> <span class="artdeco-button__text"> Message </span> </a> </footer> </section> <section id="ember364" class="artdeco-card artdeco-card--with-hover ember-view"><!----> <div class="org-people-profile-card__profile-info"> <artdeco-entity-lockup stacked="center" size="5" id="ember365" class="artdeco-entity-lockup--stacked-center artdeco-entity-lockup--size-5 artdeco-entity-lockup ember-view"><artdeco-entity-lockup-image id="ember366" class="artdeco-entity-lockup__image artdeco-entity-lockup__image--type-circle ember-view" type="circle"><a data-control-name="people_profile_card_image_link" href="/in/clementinenannan/" id="ember367" class="ember-view"> <img class="lazy-image loaded" alt="Clémentine’s profile picture" src="https://media.licdn.com/dms/image/C5603AQHR1X88QCWsnw/profile-displayphoto-shrink_100_100/0?e=1565827200&amp;v=beta&amp;t=fwXOyrczSApTvcE6A1gP-QZLIVMJ79A6L0d1dwdQ5CU" width="72" height="72"> </a> </artdeco-entity-lockup-image><artdeco-entity-lockup-content id="ember368" class="artdeco-entity-lockup__content ember-view"><artdeco-entity-lockup-title id="ember369" class="artdeco-entity-lockup__title ember-view"><a data-control-name="people_profile_card_name_link" href="/in/clementinenannan/" id="ember370" class="link-without-visited-state ember-view"> <div id="ember372" class="org-people-profile-card__profile-title t-black lt-line-clamp lt-line-clamp--single-line ember-view"> Clémentine lucie Nannan <!----></div> </a> </artdeco-entity-lockup-title> <artdeco-entity-lockup-badge id="ember373" class="artdeco-entity-lockup__badge ember-view"> <span class="artdeco-entity-lockup__degree ">·&nbsp;1st</span> <!----><!----></artdeco-entity-lockup-badge> <artdeco-entity-lockup-subtitle id="ember374" class="artdeco-entity-lockup__subtitle ember-view"> <div class="t-14 t-black--light t-normal"> <div id="ember376" class="ember-view"> <span class="lt-line-clamp__line">Marketing Management and</span> <span class="lt-line-clamp__line lt-line-clamp__line--last"> Digital student at ESSEC - F<span class="lt-line-clamp__ellipsis">... <!----> </span></span> <!----><span class="lt-line-clamp__ellipsis lt-line-clamp__ellipsis--dummy">...</span></div> </div> </artdeco-entity-lockup-subtitle><artdeco-entity-lockup-caption id="ember377" class="artdeco-entity-lockup__caption ember-view"> <div class="truncate"> ’18 Marketing </div> </artdeco-entity-lockup-caption></artdeco-entity-lockup-content> </artdeco-entity-lockup> <span> <img class="lazy-image round-image EntityPhoto-circle-1 v-align-middle loaded" alt="Vincent’s profile picture" src="https://media.licdn.com/dms/image/C4D03AQFq5VjBd4AgZQ/profile-displayphoto-shrink_100_100/0?e=1565827200&amp;v=beta&amp;t=Tt7tGo5BV12fhDTa0mMvj91f0WsArricQ0WpZXjSbKQ" width="72" height="72"> <span class="t-12 t-black t-bold"> 24 shared connections </span> </span> </div> <footer class="artdeco-card__actions"> <a data-control-name="people_profile_card_message_link" target="_blank" href="/messaging/compose/?connId=ACoAABMxF04BkeFqBF-OCOXN4MA1lD7R14Fw4zQ" id="ember378" class="artdeco-button artdeco-button--tertiary artdeco-button--fluid artdeco-button--3 ember-view"> <span class="artdeco-button__text"> Message </span> </a> </footer> </section>'; 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