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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/\s*<div\sid=\"title_feature_div[\s\S]*?<div\s*id=\"titleSection[\s\S]*?<span\s*id=\"productTitle[\s\S]*?>\s*([\s\S]*?)[\s]+<\/span> /m'; $str = '<div id="centerCol" class="centerColAlign" style="overflow: visible !important;"> <div id="title_feature_div" class="feature" data-feature-name="title" data-cel-widget="title_feature_div"> <div id="titleSection" class="a-section a-spacing-none"> <h1 id="title" class="a-size-large a-spacing-none"> <span id="productTitle" class="a-size-large"> Grommet Pliers with Qty 100, 3/16" Grommets of Brass, Steel, Copper </span> <span id="titleEDPPlaceHolder"></span> </h1> <div id="expandTitleToggle" class="a-section a-spacing-none expand aok-hidden"></div> </div> <span class="edp-feature-declaration" data-edp-feature-name="title" data-edp-asin="B0030NZSBK" data-data-hash="3386846965" data-defects="[{&quot;id&quot;:&quot;defect-mismatch-info&quot;,&quot;value&quot;:&quot;Different from product&quot;},{&quot;id&quot;:&quot;defect-missing-information&quot;,&quot;value&quot;:&quot;Missing information&quot;},{&quot;id&quot;:&quot;defect-unessential-info&quot;,&quot;value&quot;:&quot;Unimportant information&quot;},{&quot;id&quot;:&quot;defect-incorrect-information&quot;,&quot;value&quot;:&quot;Incorrect information&quot;},{&quot;id&quot;:&quot;defect-other-productinfo-issue&quot;,&quot;value&quot;:&quot;Other&quot;}]" data-metadata="CATALOG" data-feature-container-id="productTitle" data-custom-event-handler="productTitleEDPCustomEventHandler" data-display-name="Product Name" data-edit-data-state="productTitleEDPEditData" data-position="1" data-resolver="CQResolver"></span> </div> <div id="bylineInfo_feature_div" class="feature" data-feature-name="bylineInfo" data-cel-widget="bylineInfo_feature_div"> <div class="a-section a-spacing-none"> by <a id="bylineInfo" class="a-link-normal" href="/Pittsburg-Tools/b/ref=bl_dp_s_web_12684560011?ie=UTF8&amp;node=12684560011&amp;field-lbr_brands_browse-bin=Pittsburg+Tools">Pittsburg Tools</a> </div> </div> <div id="averageCustomerReviews_feature_div" class="feature" data-feature-name="averageCustomerReviews" data-cel-widget="averageCustomerReviews_feature_div"> <style type="text/css"> /* * Fix for UDP-1061. Average customer reviews has a small extra line on hover * https://omni-grok.amazon.com/xref/src/appgroup/websiteTemplates/retail/SoftlinesDetailPageAssets/udp-intl-lock/src/legacy.css?indexName=WebsiteTemplates#40 */ .noUnderline a:hover { text-decoration: none; } </style> <div id="averageCustomerReviews" class="a-spacing-none" data-asin="B0030NZSBK" data-ref="dpx_acr_pop_"> <span class="a-declarative" data-action="acrStarsLink-click-metrics" data-acrstarslink-click-metrics="{}"> <span id="acrPopover" class="reviewCountTextLinkedHistogram noUnderline" title="2.8 out of 5 stars"> <span class="a-declarative" data-action="a-popover" data-a-popover="{&quot;max-width&quot;:&quot;700&quot;,&quot;closeButton&quot;:&quot;false&quot;,&quot;position&quot;:&quot;triggerBottom&quot;,&quot;url&quot;:&quot;/gp/customer-reviews/widgets/average-customer-review/popover/ref=dpx_acr_pop_?contextId=dpx&amp;asin=B0030NZSBK&quot;}"> <a href="javascript:void(0)" class="a-popover-trigger a-declarative"> <i class="a-icon a-icon-star a-star-3"><span class="a-icon-alt">2.8 out of 5 stars</span></i> <i class="a-icon a-icon-popover"></i></a> </span> <span class="a-letter-space"></span> </span> </span> <span class="a-letter-space"></span> <span class="a-declarative" data-action="acrLink-click-metrics" data-acrlink-click-metrics="{}"> <a id="acrCustomerReviewLink" class="a-link-normal" href="#customerReviews"> <span id="acrCustomerReviewText" class="a-size-base">25 customer reviews</span> </a> </span> <script type="text/javascript"> P.when(\'A\', \'ready\').execute(function(A) { A.declarative(\'acrLink-click-metrics\', \'click\', { "allowLinkDefault" : true }, function(event){ if(window.ue) { ue.count("acrLinkClickCount", (ue.count("acrLinkClickCount") || 0) + 1); } }); }); </script> <script type="text/javascript"> P.when(\'A\', \'cf\').execute(function(A) { A.declarative(\'acrStarsLink-click-metrics\', \'click\', { "allowLinkDefault" : true }, function(event){ if(window.ue) { ue.count("acrStarsLinkWithPopoverClickCount", (ue.count("acrStarsLinkWithPopoverClickCount") || 0) + 1); } }); }); </script> </div> </div> <div id="ask_feature_div" class="feature" data-feature-name="ask" data-cel-widget="ask_feature_div"> </div> <div id="acBadge_feature_div" class="feature" data-feature-name="acBadge" data-cel-widget="acBadge_feature_div"> <script type="a-state" data-a-state="{&quot;key&quot;:&quot;acState&quot;}">{"acAsin":"B0030NZSBK"}</script> </div> <div id="zeitgeistBadge_feature_div" class="feature" data-feature-name="zeitgeistBadge" data-cel-widget="zeitgeistBadge_feature_div"> </div> <div id="socialFabric_feature_div" class="feature" data-feature-name="socialFabric" data-cel-widget="socialFabric_feature_div"> </div> <hr> <div id="desktop_unifiedPrice" class="feature" data-feature-name="desktop_unifiedPrice" data-cel-widget="desktop_unifiedPrice"> <div id="unifiedPrice_feature_div" class="feature" data-feature-name="unifiedPrice" data-cel-widget="unifiedPrice_feature_div"> <div id="honeyDiv" class="honeyDiv" style="display: flex; flex-direction: row; margin-top: 5px; margin-bottom: 10px;"><div id="optimusDiv" class="optimusDiv" style="margin-right: 5px;"><div data-reactroot="" data-radium="true"><style>div#honeyDiv.honeyDiv *{color: #292a2a; letter-spacing: initial; font-family: SuisseIntl, \'Open Sans\', sans-serif;}div#honeyDiv.honeyDiv span{color: inherit; background-image: none;}div#honeyDiv.honeyDiv{margin-bottom: 10px;}div#honeyDiv.honeyDiv > div > div{display: inline;}</style><div data-radium="true" style="position: relative; float: left; left: initial; top: 7px; right: 44px;"></div><div id="honey" data-radium="true" style="display: inline-flex;"><div class="h-badge-container"><button id="optimus:badge" type="submit" class="h-badge h-optimus h-mid h-condense-lock"><div class="h-icon"><div class="h-icon" style="display: flex;"><span class="v2-icon-honey-18 h-fill" style="color: rgb(255, 114, 39);"></span></div></div><div class="h-copy">Best Deal</div></button><div class="h-badge-child-container"></div></div></div><style></style></div></div><div id="dropListDiv" class="dropListDiv" style="margin-right: 5px;"><div data-reactroot="" data-radium="true"><style>div#honeyDiv.honeyDiv *{font-family: SuisseIntl, \'Open Sans\', sans-serif;}</style><div id="honey" data-radium="true" style="display: inline-flex;"><div data-radium="true"><div><div class="h-badge-container"><button id="dropListBadge_1_B0030NZSBK" type="submit" class="h-badge h-droplist h-mid h-is-condensed"><div class="h-icon h-icon-with-super"><div class="h-icon" style="display: flex;"><span class="v2-icon-honey-18 h-fill" style="color: rgb(255, 114, 39);"></span></div><div class="h-icon-super h-icon-add"><div class="h-icon" style="display: flex;"><span class="v2-icon-add-tiny-16 h-fill" style="color: rgb(255, 114, 39);"></span></div></div></div><div class="h-copy">Add to Droplist</div></button><div class="h-badge-child-container"></div></div></div></div></div><style></style></div></div></div><div id="price" class="a-section a-spacing-small"> <table class="a-lineitem"> <tbody><tr id="priceblock_ourprice_row"> <td id="priceblock_ourprice_lbl" class="a-color-secondary a-size-base a-text-right a-nowrap">Price:</td> <td class="a-span12"> <span id="priceblock_ourprice" class="a-size-medium a-color-price">$10.12</span> <span id="ourprice_shippingmessage"> <span id="priceBadging_feature_div" class="feature" data-feature-name="priceBadging" data-cel-widget="priceBadging_feature_div"> <i class="a-icon-wrapper a-icon-prime-with-text a-color-secondary aok-nowrap"><i class="a-icon a-icon-prime" role="img" aria-label=" | <b>FREE</b> One-Day"></i><span class="a-icon-text"> | <b>FREE</b> One-Day</span></i> </span> </span> </td> </tr> <tr id="priceblock_snsupsell_row" class="aok-hidden"> <td colspan="2"> <span class="a-size-base a-color-price"> </span> </td> </tr> </tbody></table> </div> </div> </div> <div id="pmpux_feature_div" class="feature" data-feature-name="pmpux" data-cel-widget="pmpux_feature_div"> </div> <div id="issuancePriceblockAmabot_feature_div" class="feature" data-feature-name="issuancePriceblockAmabot" data-cel-widget="issuancePriceblockAmabot_feature_div"> </div> <div id="alternativeOfferEligibilityMessaging_feature_div" class="feature" data-feature-name="alternativeOfferEligibilityMessaging" data-cel-widget="alternativeOfferEligibilityMessaging_feature_div"> </div> <div id="promiseBasedBadge_feature_div" class="feature" data-feature-name="promiseBasedBadge" data-cel-widget="promiseBasedBadge_feature_div"> </div> <div id="applicablePromotionList_feature_div" class="feature" data-feature-name="applicablePromotionList" data-cel-widget="applicablePromotionList_feature_div"> </div> <div id="availability_feature_div" class="feature" data-feature-name="availability" data-cel-widget="availability_feature_div"> </div> <div id="globalStoreBadgePopover_feature_div" class="feature" data-feature-name="globalStoreBadgePopover" data-cel-widget="globalStoreBadgePopover_feature_div"> </div> <div id="holidayDeliveryMessage_feature_div" class="feature" data-feature-name="holidayDeliveryMessage" data-cel-widget="holidayDeliveryMessage_feature_div"> </div> <div id="dpFastTrack_feature_div" class="feature" data-feature-name="dpFastTrack" data-cel-widget="dpFastTrack_feature_div"> </div> <div id="businessOnlyItem_feature_div" class="feature" data-feature-name="businessOnlyItem" data-cel-widget="businessOnlyItem_feature_div"> </div> <div id="shipsFromSoldBy_feature_div" class="feature" data-feature-name="shipsFromSoldBy" data-cel-widget="shipsFromSoldBy_feature_div"> </div> <div id="productSupportAndReturnPolicy_feature_div" class="feature" data-feature-name="productSupportAndReturnPolicy" data-cel-widget="productSupportAndReturnPolicy_feature_div"> <!-- productSupportAndReturnPolicy --> </div> <div id="businessPricing_feature_div" class="feature" data-feature-name="businessPricing" data-cel-widget="businessPricing_feature_div"> </div> <div id="smileEligibility_feature_div" class="feature" data-feature-name="smileEligibility" data-cel-widget="smileEligibility_feature_div"> </div> <div id="holidayAvailabilityMessage_feature_div" class="feature" data-feature-name="holidayAvailabilityMessage" data-cel-widget="holidayAvailabilityMessage_feature_div"> </div> <div id="productSample_feature_div" class="feature" data-feature-name="productSample" data-cel-widget="productSample_feature_div"> </div> <div id="twister_feature_div" class="feature" data-feature-name="twister" data-cel-widget="twister_feature_div"> </div> <div id="addServices_feature_div" class="feature" data-feature-name="addServices" data-cel-widget="addServices_feature_div"> <script type="text/javascript">(function(f) {f(window.P._namespace("VAS_DSC"));}(function(P) { if (typeof uet === \'function\') { uet(\'bb\',"LocalServicesWidget", {wb: 1}); //timestamp body-begin } }));</script><input type="hidden" id="vas-zipCodeValidationRegexString" name="vas-zipCodeValidationRegexString" value=""> <script type="a-state" data-a-state="{&quot;key&quot;:&quot;smartShelfVASInfo&quot;}">{"hideSmartShelf":false}</script><!-- if warranty SI is eligible to be shown https://w.amazon.com/bin/view/VAS/Discovery/ServiceInterstitialDisplayLogic--> <script type="a-state" data-a-state="{&quot;key&quot;:&quot;vas-common-vm&quot;}">{"isProductAvailable":true,"zipCode":"","attachToLdbb":false,"showEnhancedUpsellBundle":"false","multiQuantityPurchaseEnabled":false,"hijackMBCATC":false,"productAsin":"B0030NZSBK","serviceAsin":"","sessionId":"","showSIATC":false,"productPTD":"TOYS_AND_GAMES","showUnifiedGuruExperience":false,"doRedirect":false,"showSTSServiceInterstitial":false,"hijackATC":false,"productWDG":"home_improvement_display_on_website","isCBM":false,"defaultServiceAsinToOffer":"","buyboxPrice":"$10.12","isWarrantyPresent":false,"shouldSuppressWidget":false,"offerListingID":"","isVariationalParent":false}</script><script type="text/javascript">(function(f) {f(window.P._namespace("VAS_DSC"));}(function(P) { if (typeof uex === \'function\') { uex(\'ld\',"LocalServicesWidget", {wb: 1}); //send the metrics to the server } }));</script> </div> <div id="clickToContact_feature_div" class="feature" data-feature-name="clickToContact" data-cel-widget="clickToContact_feature_div"> </div> <div id="amazonCertifiedBadge_feature_div" class="feature" data-feature-name="amazonCertifiedBadge" data-cel-widget="amazonCertifiedBadge_feature_div"> </div> <div id="smartHomeWidget_feature_div" class="feature" data-feature-name="smartHomeWidget" data-cel-widget="smartHomeWidget_feature_div"> </div> <div id="renewedProgramDescriptionAtf_feature_div" class="feature" data-feature-name="renewedProgramDescriptionAtf" data-cel-widget="renewedProgramDescriptionAtf_feature_div"> </div> <div id="featurebullets_feature_div" class="feature" data-feature-name="featurebullets" data-cel-widget="featurebullets_feature_div"> <div id="feature-bullets" class="a-section a-spacing-medium a-spacing-top-small"> <ul class="a-unordered-list a-vertical a-spacing-none"> <div id="hsx-rpp-bullet-fits-message" class="aok-hidden"> <div class="a-box a-alert-inline a-alert-inline-success hsx-rpp-fitment-bullets"><div class="a-box-inner a-alert-container"><i class="a-icon a-icon-alert"></i><div class="a-alert-content"> This fits your&nbsp;<span class="hsx-rpp-bullet-model-info"></span>. </div></div></div> </div> <li id="replacementPartsFitmentBullet" data-doesntfitmessage="We\'re not sure this item fits your " data-fitsmessage="This fits your " class="aok-hidden"><span class="a-list-item"> <span id="replacementPartsFitmentBulletInner"> <a class="a-link-normal hsx-rpp-fitment-focus" href="#">Make sure this fits</a> <span>by entering your model number.</span> </span> </span></li> <script type="text/javascript"> P.when("ReplacementPartsBulletLoader").execute(function(module){ module.initializeDPX(); }) </script> <li><span class="a-list-item"> Grommet tool for use with 3/16" (0.187") grommets </span></li> <li><span class="a-list-item"> Soft handle tool with swing mechanism to lock closed </span></li> <li><span class="a-list-item"> 5 3/4" long, 3/4" jaw opening </span></li> <li><span class="a-list-item"> Includes total of 100 grommets of steel, copper, brass </span></li> <li><span class="a-list-item"> Chrome finish with padded handles </span></li> </ul> <!-- Loading EDP related metadata --> <span class="edp-feature-declaration" data-edp-feature-name="featurebullets" data-edp-asin="B0030NZSBK" data-data-hash="1249920702" data-defects="[{&quot;id&quot;:&quot;defect-mismatch-info&quot;,&quot;value&quot;:&quot;Different from product&quot;},{&quot;id&quot;:&quot;defect-missing-information&quot;,&quot;value&quot;:&quot;Missing information&quot;},{&quot;id&quot;:&quot;defect-unessential-info&quot;,&quot;value&quot;:&quot;Unimportant information&quot;},{&quot;id&quot;:&quot;defect-other-productinfo-issue&quot;,&quot;value&quot;:&quot;Other&quot;}]" data-metadata="CATALOG" data-feature-container-id="" data-custom-event-handler="" data-display-name="Bullet Points" data-edit-data-state="featureBulletsEDPEditData" data-position="" data-resolver="CQResolver"></span> <span class="caretnext">›</span> <a id="seeMoreDetailsLink" class="a-link-normal" href="#productDetails">See more product details</a> </div> </div> <div id="globalStoreInfoBullets_feature_div" class="feature" data-feature-name="globalStoreInfoBullets" data-cel-widget="globalStoreInfoBullets_feature_div"> </div> <div id="HLCXComparisonJumplink_feature_div"></div> <div id="vendorPoweredCoupon_feature_div" class="feature" data-feature-name="vendorPoweredCoupon" data-cel-widget="vendorPoweredCoupon_feature_div"> </div> <div id="addOnItem_feature_div" class="feature" data-feature-name="addOnItem" data-cel-widget="addOnItem_feature_div"> </div> <div id="giftcard-holiday-availability-messaging_feature_div" class="feature" data-feature-name="giftCardHolidayAvailabilityMessaging" data-cel-widget="giftcard-holiday-availability-messaging_feature_div"> <!--giftCardHolidayAvailabilityMessaging_placeholder--> </div> <div id="andonCord_feature_div" class="feature" data-feature-name="andonCord" data-cel-widget="andonCord_feature_div"> </div> <div id="olp_feature_div" class="feature" data-feature-name="olp" data-cel-widget="olp_feature_div"> <div id="olp-upd-new" class="a-section a-spacing-small a-spacing-top-small"> <span><a href="/gp/offer-listing/B0030NZSBK/ref=dp_olp_new_mbc?ie=UTF8&amp;condition=new"><b>New</b> (11) from $10.12</a></span> <i class="a-icon a-icon-prime a-icon-medium"></i> </div> </div> <div id="edpIngress_feature_div" class="feature" data-feature-name="edpIngress" data-cel-widget="edpIngress_feature_div"> <span id="edpIngressContainer"> <span class="edpIngressIcon"></span> <a id="edpIngress" class="a-link-normal a-declarative" href="javascript://"> <span class="edpIngressText">Report incorrect product information.</span></a> </span> <div class="a-section a-spacing-none a-spacing-top-mini"></div> </div> <div id="newerVersion_feature_div" class="feature" data-feature-name="newerVersion" data-cel-widget="newerVersion_feature_div"> </div> <div id="valuePick_feature_div" class="feature" data-feature-name="valuePick" data-cel-widget="valuePick_feature_div"> </div> <div id="certifiedRefurbishedVersion_feature_div" class="feature" data-feature-name="certifiedRefurbishedVersion" data-cel-widget="certifiedRefurbishedVersion_feature_div"> </div> <div id="liveExpert_feature_div" class="feature" data-feature-name="liveExpert" data-cel-widget="liveExpert_feature_div"> </div> <div id="recommendations_feature_div" class="feature" data-feature-name="recommendations" data-cel-widget="recommendations_feature_div"> </div> <div id="productAlert_feature_div" class="feature" data-feature-name="productAlert" data-cel-widget="productAlert_feature_div"> </div> <div id="promotionalAddon_feature_div" class="feature" data-feature-name="promotionalAddon" data-cel-widget="promotionalAddon_feature_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