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

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"<a class=\"Anchor-qkwhxv-0 cRgrlM\" href=\"([^\"]+)\"" test_str = "<div class=\"LoadMoreWrapper__Container-hxv6br-0 rnteU\" id=\"00000142-9228-d1f0-a5c6-b2fd817d0000\" name=\"cybersecurity\" spacing=\"6\"><p class=\"sc-bdVaJa iEuuK\">The Latest</p><div class=\"ntx-mediaobject-container\"><div class=\"jpvx17-0-Box-cwadsP eISNqp\" spacing=\"5\"><div class=\"jpvx17-0-Box-cwadsP gfFbpn\"><h3 class=\"sc-bdVaJa ixAtVd\"><a class=\"Anchor-qkwhxv-0 cRgrlM\" href=\"https://money.usnews.com/money/personal-finance/family-finance/articles/2018-06-22/10-things-to-do-immediately-after-your-identity-is-stolen\" letter-spacing=\"0.6\">10 Things to Do If Your Identity Is Stolen</a></h3><p class=\"Hide-l1npyw-0 iLzjOL Paragraph-fqygwe-0 foOETH\" size=\"3\" spacing=\"4\">Think someone has your personal information? Take these steps to protect yourself.</p><p class=\"Hide-l1npyw-0 iLzjOL fqygwe-0-Paragraph-hHEPzZ ggYInA\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt bplooz\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt jQyjzQ\" size=\"2\"><span></span>Maryalene LaPonsie</span></span><span> <!-- -->June 22, 2018</span></p></div><div class=\"jpvx17-0-Box-cwadsP eWPQPg\"><a class=\"Anchor-qkwhxv-0 iRvSIy\" href=\"https://money.usnews.com/money/personal-finance/family-finance/articles/2018-06-22/10-things-to-do-immediately-after-your-identity-is-stolen\" letter-spacing=\"0.6\"><picture class=\"Image__Picture-s1o4eta-0 dHmORe\"><source srcset=\"https://www.usnews.com/dims4/USNEWS/11b477b/2147483647/crop/500x333%2B0%2B0/resize/303x202/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2Ffb%2F7e%2Fc95bd58f4c8b9f21b7696e907e8d%2Fresizes%2F500%2F150731-identitystolen-stock.jpg\" media=\"(min-width: 640px)\"><img src=\"https://www.usnews.com/dims4/USNEWS/cc27d02/2147483647/crop/333x333%2B74%2B0/resize/84x84/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2Ffb%2F7e%2Fc95bd58f4c8b9f21b7696e907e8d%2Fresizes%2F500%2F150731-identitystolen-stock.jpg\" class=\"MediaObject__MediaImage-qwnn1d-0 gkjlrf Image-s1o4eta-2 jloNmB\"></picture></a></div></div><div class=\"jpvx17-0-Box-cwadsP eISNqp\" spacing=\"5\"><div class=\"jpvx17-0-Box-cwadsP gfFbpn\"><h3 class=\"sc-bdVaJa ixAtVd\"><a class=\"Anchor-qkwhxv-0 cRgrlM\" href=\"https://www.usnews.com/news/best-states/nevada/articles/2018-06-01/cybersecurity-education-growing-in-nevada-as-risks-increase\" letter-spacing=\"0.6\">Cybersecurity Education Growing in Nevada as Risks Increase</a></h3><p class=\"Hide-l1npyw-0 iLzjOL Paragraph-fqygwe-0 foOETH\" size=\"3\" spacing=\"4\">Those who step into this virtual world will face thieving cyber gangs who are on the hunt for electronic bikes in Europe.</p><p class=\"Hide-l1npyw-0 iLzjOL fqygwe-0-Paragraph-hHEPzZ ggYInA\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt bplooz\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt jQyjzQ\" size=\"2\"><span></span>Associated Press</span></span><span> <!-- -->June 1, 2018</span></p></div><div class=\"jpvx17-0-Box-cwadsP eWPQPg\"><a class=\"Anchor-qkwhxv-0 iRvSIy\" href=\"https://www.usnews.com/news/best-states/nevada/articles/2018-06-01/cybersecurity-education-growing-in-nevada-as-risks-increase\" letter-spacing=\"0.6\"><picture class=\"Image__Picture-s1o4eta-0 dHmORe\"><source srcset=\"https://www.usnews.com/dims4/USNEWS/fb9d276/2147483647/thumbnail/303x202/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2F40%2F1dbb0f2ec0ba0b3e6aa6e523ad2ac5%2Fresizes%2F500%2Fmedia%3A529eea2ecbd644b3a52e9865c09ede2dExchange_Cybersecurity_Education_67549.jpg\" media=\"(min-width: 640px)\"><img src=\"https://www.usnews.com/dims4/USNEWS/a254de6/2147483647/thumbnail/84x84/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2F40%2F1dbb0f2ec0ba0b3e6aa6e523ad2ac5%2Fresizes%2F500%2Fmedia%3A529eea2ecbd644b3a52e9865c09ede2dExchange_Cybersecurity_Education_67549.jpg\" class=\"MediaObject__MediaImage-qwnn1d-0 gkjlrf Image-s1o4eta-2 jloNmB\"></picture></a></div></div><div class=\"Hide-l1npyw-0 BSIOt jpvx17-0-Box-cwadsP kicwrf\" type=\"rect_\" spacing=\"5\"><div id=\"ad\" class=\"ad \" data-ad-type=\"rect_\" data-dimensions=\"300x250,300x600\" data-targeting=\"{}\"></div></div><div class=\"Hide-l1npyw-0 biIYek jpvx17-0-Box-cwadsP bVnTJr\" type=\"lb_\" spacing=\"5\"><div id=\"ad\" class=\"ad \" data-ad-type=\"lb_\" data-dimensions=\"728x90\" data-targeting=\"{}\"></div></div><div class=\"jpvx17-0-Box-cwadsP eISNqp\" spacing=\"5\"><div class=\"jpvx17-0-Box-cwadsP gfFbpn\"><h3 class=\"sc-bdVaJa ixAtVd\"><a class=\"Anchor-qkwhxv-0 cRgrlM\" href=\"https://www.usnews.com/news/healthcare-of-tomorrow/articles/2018-05-25/security-of-medical-devices-is-latest-health-care-concern\" letter-spacing=\"0.6\">Can a Hospital Room Be Hacked?</a></h3><p class=\"Hide-l1npyw-0 iLzjOL Paragraph-fqygwe-0 foOETH\" size=\"3\" spacing=\"4\">Cyberattacks on medical devices could mean myriad problems for hospitals and other health care providers.</p><p class=\"Hide-l1npyw-0 iLzjOL fqygwe-0-Paragraph-hHEPzZ ggYInA\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt bplooz\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt jQyjzQ\" size=\"2\"><span></span>Terena Bell</span></span><span> <!-- -->May 25, 2018</span></p></div><div class=\"jpvx17-0-Box-cwadsP eWPQPg\"><a class=\"Anchor-qkwhxv-0 iRvSIy\" href=\"https://www.usnews.com/news/healthcare-of-tomorrow/articles/2018-05-25/security-of-medical-devices-is-latest-health-care-concern\" letter-spacing=\"0.6\"><picture class=\"Image__Picture-s1o4eta-0 dHmORe\"><source srcset=\"https://www.usnews.com/dims4/USNEWS/c7a4da6/2147483647/thumbnail/303x202/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2F73%2F980b3f4f4eb7fcf9bf8df3cae5907b%2F45876FE_PR_080913_Emptyhospitalroom.jpg\" media=\"(min-width: 640px)\"><img src=\"https://www.usnews.com/dims4/USNEWS/43bd6e9/2147483647/thumbnail/84x84/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2F73%2F980b3f4f4eb7fcf9bf8df3cae5907b%2F45876FE_PR_080913_Emptyhospitalroom.jpg\" class=\"MediaObject__MediaImage-qwnn1d-0 gkjlrf Image-s1o4eta-2 jloNmB\"></picture></a></div></div><div class=\"jpvx17-0-Box-cwadsP eISNqp\" spacing=\"5\"><div class=\"jpvx17-0-Box-cwadsP gfFbpn\"><h3 class=\"sc-bdVaJa ixAtVd\"><a class=\"Anchor-qkwhxv-0 cRgrlM\" href=\"https://www.usnews.com/news/best-countries/articles/2018-05-24/data-heavy-reliance-on-social-media-aligns-with-trust-in-private-companies\" letter-spacing=\"0.6\">Who Will Fix Internet Privacy Problems? </a></h3><p class=\"Hide-l1npyw-0 iLzjOL Paragraph-fqygwe-0 foOETH\" size=\"3\" spacing=\"4\">New and unprecedented European Union internet rules may still be insufficient at a time of deep privacy concerns globally.</p><p class=\"Hide-l1npyw-0 iLzjOL fqygwe-0-Paragraph-hHEPzZ ggYInA\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt bplooz\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt jQyjzQ\" size=\"2\"><span></span>Paul D. Shinkman</span></span><span> <!-- -->May 24, 2018</span></p></div><div class=\"jpvx17-0-Box-cwadsP eWPQPg\"><a class=\"Anchor-qkwhxv-0 iRvSIy\" href=\"https://www.usnews.com/news/best-countries/articles/2018-05-24/data-heavy-reliance-on-social-media-aligns-with-trust-in-private-companies\" letter-spacing=\"0.6\"><picture class=\"Image__Picture-s1o4eta-0 dHmORe\"><source srcset=\"https://www.usnews.com/dims4/USNEWS/884107c/2147483647/crop/494x329%2B0%2B0/resize/303x202/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2F1b%2F91%2Fc4cc2d5e4f5e8a19ecbff43a7419%2Fresizes%2F500%2F180524-euprivacy-editorial.jpg\" media=\"(min-width: 640px)\"><img src=\"https://www.usnews.com/dims4/USNEWS/7c4a0a1/2147483647/crop/329x329%2B0%2B0/resize/84x84/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2F1b%2F91%2Fc4cc2d5e4f5e8a19ecbff43a7419%2Fresizes%2F500%2F180524-euprivacy-editorial.jpg\" class=\"MediaObject__MediaImage-qwnn1d-0 gkjlrf Image-s1o4eta-2 jloNmB\"></picture></a></div></div><div class=\"jpvx17-0-Box-cwadsP eISNqp\" spacing=\"5\"><div class=\"jpvx17-0-Box-cwadsP gfFbpn\"><h3 class=\"sc-bdVaJa ixAtVd\"><a class=\"Anchor-qkwhxv-0 cRgrlM\" href=\"https://money.usnews.com/money/personal-finance/family-finance/articles/2018-05-22/how-to-protect-yourself-from-medical-identity-theft\" letter-spacing=\"0.6\">Protect Yourself From Medical ID Theft</a></h3><p class=\"Hide-l1npyw-0 iLzjOL Paragraph-fqygwe-0 foOETH\" size=\"3\" spacing=\"4\">A thief who uses your medical data to access treatment could harm your finances – and your health.</p><p class=\"Hide-l1npyw-0 iLzjOL fqygwe-0-Paragraph-hHEPzZ ggYInA\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt bplooz\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt jQyjzQ\" size=\"2\"><span></span>Susannah Snider</span></span><span> <!-- -->May 22, 2018</span></p></div><div class=\"jpvx17-0-Box-cwadsP eWPQPg\"><a class=\"Anchor-qkwhxv-0 iRvSIy\" href=\"https://money.usnews.com/money/personal-finance/family-finance/articles/2018-05-22/how-to-protect-yourself-from-medical-identity-theft\" letter-spacing=\"0.6\"><picture class=\"Image__Picture-s1o4eta-0 dHmORe\"><source srcset=\"https://www.usnews.com/dims4/USNEWS/0858209/2147483647/thumbnail/303x202/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2Fd2%2Ff9%2F351f0de446549f8131aefe62bddd%2Fresizes%2F500%2F140605-medicalrecords-stock.jpg\" media=\"(min-width: 640px)\"><img src=\"https://www.usnews.com/dims4/USNEWS/34458ff/2147483647/thumbnail/84x84/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2Fd2%2Ff9%2F351f0de446549f8131aefe62bddd%2Fresizes%2F500%2F140605-medicalrecords-stock.jpg\" class=\"MediaObject__MediaImage-qwnn1d-0 gkjlrf Image-s1o4eta-2 jloNmB\"></picture></a></div></div><div class=\"jpvx17-0-Box-cwadsP eISNqp\" spacing=\"5\"><div class=\"jpvx17-0-Box-cwadsP gfFbpn\"><h3 class=\"sc-bdVaJa ixAtVd\"><a class=\"Anchor-qkwhxv-0 cRgrlM\" href=\"https://money.usnews.com/investing/cryptocurrency/articles/2018-05-04/is-bitcoin-a-safe-investment\" letter-spacing=\"0.6\">Is Bitcoin a Safe Investment?</a></h3><p class=\"Hide-l1npyw-0 iLzjOL Paragraph-fqygwe-0 foOETH\" size=\"3\" spacing=\"4\">The frequent hacking of cryptocurrency exchanges serves as a warning to investors.</p><p class=\"Hide-l1npyw-0 iLzjOL fqygwe-0-Paragraph-hHEPzZ ggYInA\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt bplooz\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt jQyjzQ\" size=\"2\"><span></span>Ellen Chang</span></span><span> <!-- -->May 4, 2018</span></p></div><div class=\"jpvx17-0-Box-cwadsP eWPQPg\"><a class=\"Anchor-qkwhxv-0 iRvSIy\" href=\"https://money.usnews.com/investing/cryptocurrency/articles/2018-05-04/is-bitcoin-a-safe-investment\" letter-spacing=\"0.6\"><picture class=\"Image__Picture-s1o4eta-0 dHmORe\"><source srcset=\"https://www.usnews.com/dims4/USNEWS/d4ebfeb/2147483647/thumbnail/303x202/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2F93%2Fce%2Fac58f43b4ee2911a2a4bf03ae19d%2Fresizes%2F500%2F180504-bitcoin-stock.jpg\" media=\"(min-width: 640px)\"><img src=\"https://www.usnews.com/dims4/USNEWS/b70a2ec/2147483647/thumbnail/84x84/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2F93%2Fce%2Fac58f43b4ee2911a2a4bf03ae19d%2Fresizes%2F500%2F180504-bitcoin-stock.jpg\" class=\"MediaObject__MediaImage-qwnn1d-0 gkjlrf Image-s1o4eta-2 jloNmB\"></picture></a></div></div><div class=\"jpvx17-0-Box-cwadsP eISNqp\" spacing=\"5\"><div class=\"jpvx17-0-Box-cwadsP gfFbpn\"><h3 class=\"sc-bdVaJa ixAtVd\"><a class=\"Anchor-qkwhxv-0 cRgrlM\" href=\"https://money.usnews.com/investing/investing-101/articles/2017-11-06/best-bitcoin-wallet-of-2018\" letter-spacing=\"0.6\">The Best Bitcoin Wallet of 2018</a></h3><p class=\"Hide-l1npyw-0 iLzjOL Paragraph-fqygwe-0 foOETH\" size=\"3\" spacing=\"4\">Storing Bitcoin is just as important as buying it. With a wealth of options available, which is best?</p><p class=\"Hide-l1npyw-0 iLzjOL fqygwe-0-Paragraph-hHEPzZ ggYInA\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt bplooz\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt jQyjzQ\" size=\"2\"><span></span>John Divine</span></span><span> <!-- -->May 3, 2018</span></p></div><div class=\"jpvx17-0-Box-cwadsP eWPQPg\"><a class=\"Anchor-qkwhxv-0 iRvSIy\" href=\"https://money.usnews.com/investing/investing-101/articles/2017-11-06/best-bitcoin-wallet-of-2018\" letter-spacing=\"0.6\"><picture class=\"Image__Picture-s1o4eta-0 dHmORe\"><source srcset=\"https://www.usnews.com/dims4/USNEWS/a64643a/2147483647/crop/500x333%2B0%2B0/resize/303x202/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2F7f%2F38%2F697a1842489ba9834f10d7bd7464%2Fresizes%2F500%2F160610-bitcoin-stock.jpg\" media=\"(min-width: 640px)\"><img src=\"https://www.usnews.com/dims4/USNEWS/5857c9f/2147483647/crop/333x333%2B148%2B0/resize/84x84/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2F7f%2F38%2F697a1842489ba9834f10d7bd7464%2Fresizes%2F500%2F160610-bitcoin-stock.jpg\" class=\"MediaObject__MediaImage-qwnn1d-0 gkjlrf Image-s1o4eta-2 jloNmB\"></picture></a></div></div><div class=\"Hide-l1npyw-0 BSIOt jpvx17-0-Box-cwadsP kicwrf\" type=\"rect_\" spacing=\"5\"><div id=\"ad\" class=\"ad \" data-ad-type=\"rect_\" data-dimensions=\"300x250,300x600\" data-targeting=\"{}\"></div></div><div class=\"Hide-l1npyw-0 biIYek jpvx17-0-Box-cwadsP bVnTJr\" type=\"lb_\" spacing=\"5\"><div id=\"ad\" class=\"ad \" data-ad-type=\"lb_\" data-dimensions=\"728x90\" data-targeting=\"{}\"></div></div><div class=\"jpvx17-0-Box-cwadsP eISNqp\" spacing=\"5\"><div class=\"jpvx17-0-Box-cwadsP gfFbpn\"><h3 class=\"sc-bdVaJa ixAtVd\"><a class=\"Anchor-qkwhxv-0 cRgrlM\" href=\"https://money.usnews.com/money/personal-finance/family-finance/articles/2018-04-17/4-ways-millennials-can-avoid-online-financial-scams\" letter-spacing=\"0.6\">Millennials: 4 Ways to Avoid Money Scams</a></h3><p class=\"Hide-l1npyw-0 iLzjOL Paragraph-fqygwe-0 foOETH\" size=\"3\" spacing=\"4\">A new FTC report shows millennials are more likely to fall for fraud than older generations.</p><p class=\"Hide-l1npyw-0 iLzjOL fqygwe-0-Paragraph-hHEPzZ ggYInA\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt bplooz\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt jQyjzQ\" size=\"2\"><span></span>Geoff Williams</span></span><span> <!-- -->April 17, 2018</span></p></div><div class=\"jpvx17-0-Box-cwadsP eWPQPg\"><a class=\"Anchor-qkwhxv-0 iRvSIy\" href=\"https://money.usnews.com/money/personal-finance/family-finance/articles/2018-04-17/4-ways-millennials-can-avoid-online-financial-scams\" letter-spacing=\"0.6\"><picture class=\"Image__Picture-s1o4eta-0 dHmORe\"><source srcset=\"https://www.usnews.com/dims4/USNEWS/4a6ff8c/2147483647/thumbnail/303x202/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2Feb%2F20%2F3b257d834375b4d600b264fc9e93%2Fresizes%2F500%2F180417-upsetmillennialworker-stock.jpg\" media=\"(min-width: 640px)\"><img src=\"https://www.usnews.com/dims4/USNEWS/87337cc/2147483647/thumbnail/84x84/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2Feb%2F20%2F3b257d834375b4d600b264fc9e93%2Fresizes%2F500%2F180417-upsetmillennialworker-stock.jpg\" class=\"MediaObject__MediaImage-qwnn1d-0 gkjlrf Image-s1o4eta-2 jloNmB\"></picture></a></div></div><div class=\"jpvx17-0-Box-cwadsP eISNqp\" spacing=\"5\"><div class=\"jpvx17-0-Box-cwadsP gfFbpn\"><h3 class=\"sc-bdVaJa ixAtVd\"><a class=\"Anchor-qkwhxv-0 cRgrlM\" href=\"https://www.usnews.com/news/national-news/articles/2018-04-13/can-the-law-stop-ransomware\" letter-spacing=\"0.6\">Can the Law Stop Ransomware?</a></h3><p class=\"Hide-l1npyw-0 iLzjOL Paragraph-fqygwe-0 foOETH\" size=\"3\" spacing=\"4\">Lawmakers across the U.S. have made even the possession of malware illegal – whether that will deter attacks, however, is a different story.</p><p class=\"Hide-l1npyw-0 iLzjOL fqygwe-0-Paragraph-hHEPzZ ggYInA\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt bplooz\" size=\"2\"><span class=\"aabx0k-0-Span-juOiwt jQyjzQ\" size=\"2\"><span></span>Alan Neuhauser</span></span><span> <!-- -->April 13, 2018</span></p></div><div class=\"jpvx17-0-Box-cwadsP eWPQPg\"><a class=\"Anchor-qkwhxv-0 iRvSIy\" href=\"https://www.usnews.com/news/national-news/articles/2018-04-13/can-the-law-stop-ransomware\" letter-spacing=\"0.6\"><picture class=\"Image__Picture-s1o4eta-0 dHmORe\"><source srcset=\"https://www.usnews.com/dims4/USNEWS/532da2a/2147483647/thumbnail/303x202/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2F90%2Fe0%2F7c4249154b4680068bd0e1ba6d3a%2Fresizes%2F500%2F180410-ransomeware-editorial.jpg\" media=\"(min-width: 640px)\"><img src=\"https://www.usnews.com/dims4/USNEWS/87a73a7/2147483647/thumbnail/84x84/quality/85/?url=http%3A%2F%2Fmedia.beam.usnews.com%2F90%2Fe0%2F7c4249154b4680068bd0e1ba6d3a%2Fresizes%2F500%2F180410-ransomeware-editorial.jpg\" class=\"MediaObject__MediaImage-qwnn1d-0 gkjlrf Image-s1o4eta-2 jloNmB\"></picture></a></div></div></div><button class=\"s10zmu5c-0-Button-kDSBcD hUlYdQ\"><div class=\"button-content\">Load More</div></button></div>" matches = re.finditer(regex, test_str, re.MULTILINE) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum))) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

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 Python, please visit: https://docs.python.org/3/library/re.html