# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"<a\s+(:[^>]*?\s+)?href=\"([^\"]*)\">"
test_str = ("<p>We’ve said it before—the '90s are back in a big way. While you might be a little uneasy about <a href=\"http://www.bravotv.com/the-daily-dish/chokers-even-adults-can-wear\">embracing chokers</a> or <a href=\"http://www.bravotv.com/the-daily-dish/velvet-fashion-and-accessories\">dressing head-to-toe in velvet</a>, the backpack is something we can all get on board with. And we’re not talking about the back-to-school variety. Designers from <a href=\"https://us.burberry.com/the-medium-rucksack-in-technical-nylonleather-p40166221\">Burberry</a> to <a href=\"https://us.burberry.com/the-medium-rucksack-in-technical-nylonleather-p40166221\">Target</a> are scrambling to offer fashionable backpacks to the masses this fall, and rightly so. Has there ever been a more functional bag?</p>\n\n"
"<p>As a mom to three little ones, I need a vessel that can hold sippy cups, pull-ups, and everything in between—but I’ve never met a diaper bag that I actually liked. That’s why I’m so overjoyed by the reemergence of the backpack. I can use it as a purse for me and as a trough for all my toddler’s necessities, and my hands are free and my shoulder’s not aching from lugging around a 20-pound handbag. I’ve rounded up some of the cutest (and CHEAPEST!) options available online right now, so whether you're looking for something structured or slouchy, sedate or look-at-me-now!-loud, we've got you covered. The best part? Each one is as pretty as it is practical.</p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">1</span><span class=\"listicle__title\">ASOS</span></h2></p>\n\n"
"<p><a href=\"http://us.asos.com/asos/asos-croc-square-backpack/prd/7145675?iid=7145675&affid=10607&transaction_id=102d9ab659ee5a2a2afbc4227fb95a&pubref=1023\">Croc Square Backpack, $43</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">2</span><span class=\"listicle__title\">Skinnydip London</span></h2></p>\n\n"
"<p><a href=\"http://us.skinnydiplondon.com/collections/bags/products/woven-backpack\">Woven Backpack, SALE $32 (Originally $60)</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">3</span><span class=\"listicle__title\">Boohoo.com</span></h2></p>\n\n"
"<p><a href=\"http://us.boohoo.com/isabel-simple-side-zip-backpack/DZZ70713.html?color=131\">Isabel Simple Side Zip Backpack, SALE $16 (Originally $22)</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">4</span><span class=\"listicle__title\">Zara</span></h2></p>\n\n"
"<p><a href=\"http://www.zara.com/us/en/woman/bags/backpacks/pompom-crossbody-backpack-c765517p3769015.html\">Pompom Crossbody Backpack, $49.90</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">5</span><span class=\"listicle__title\">ASOS</span></h2></p>\n\n"
"<p><a href=\"http://us.asos.com/asos/asos-front-zip-backpack-with-dog-clip-and-tassel/prd/5902722?iid=5902722&clr=Black&SearchQuery=&cid=12496&pgesize=204&pge=0&totalstyles=251&gridsize=3&gridrow=23&gridcolumn=3\">Front Zip Backpack With Dog Clip And Tassel, $43</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">6</span><span class=\"listicle__title\">Tommy Hilfiger</span></h2></p>\n\n"
"<p><a href=\"http://www1.macys.com/shop/product/tommy-hilfiger-sporty-neoprene-stars-mini-backpack?ID=2769277&pla_country=US&CAGPSPN=pla&CAWELAID=120156340006456711&CAAGID=14183164687&CATCI=pla-78768411727&catargetid=120156340000915303&cadevice=c&cm_mmc=Google_Handbags_PLA-_-G_PLA_Handbags_Tommy+Hilfiger_Tommy+Hilfiger-_-69538618807-_-pg60036_c_kclickid_c5a7d5e4-4374-4af8-80a5-b0abf378ebc6&trackingid=477x60036&gclid=CKnm9KPEptACFRZMDQodUU4DgQ\">Sporty Neoprene Stars Mini Backpack, SALE $46.19 (Originally $88)</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">7</span><span class=\"listicle__title\">GoJane</span></h2></p>\n\n"
"<p><a href=\"http://www.gojane.com/114728.html\">Travel Buddy Mini Backpack, SALE $27.95 (Originally $35)</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">8</span><span class=\"listicle__title\">Target</span></h2></p>\n\n"
"<p><a href=\"http://www.target.com/p/women-s-vertical-buckles-backpack-faux-leather-handbag-merona/-/A-16917478?clkid=ad465660Nef0c39a72e8ea0fac8b1f6c1&lnm=81938&afid=POPSUGAR&ref=tgt_adv_xasd0002\">Merona Vertical Buckles Backpack, $34.99</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">9</span><span class=\"listicle__title\">H&M</span></h2></p>\n\n"
"<p><a href=\"http://www.hm.com/us/product/56495?article=56495-B&cm_vc=SEARCH\">Backpack, $29.99</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">10</span><span class=\"listicle__title\">Aldo</span></h2></p>\n\n"
"<p><a href=\"http://www.aldoshoes.com/us/en_US/Handbags/Backpacks/c/345/Tilzer/p/40265783-62\">Tilzer, SALE $34.98 (Originally $50)</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">11</span><span class=\"listicle__title\">Herschel Supply Co.</span></h2></p>\n\n"
"<p> </p>\n\n"
"<p> </p>\n\n"
"<p><a class=\"asdf\" href=\"http://hbx.com/brands/herschel-supply-co/packable-daypack-1?utm_source=affiliates&utm_medium=commissionjunction&utm_campaign=ShopStyle.com\">Packable Daypack, SALE $19.98 (Originially $35)</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">12</span><span class=\"listicle__title\">Society New York</span></h2></p>\n\n"
"<p><a href=\"https://www.amazon.com/dp/B01DOOL12Y/ref=asc_df_B01DOOL12Y4629111?smid=ATVPDKIKX0DER&linkCode=df0&creative=395093&creativeASIN=B01DOOL12Y&tag=wwwshopstylec-20&ascsubtag=2238735633\">Women's Backpack with Tassel, SALE $18 ($59)</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">13</span><span class=\"listicle__title\">Aldo</span></h2></p>\n\n"
"<p><a href=\"https://www.amazon.com/Aldo-DEROLPHI-Womens-Derolphi-Taupe/dp/B01H6GIXYA/ref=sr_1_1?srs=7780575011&ie=UTF8&qid=1479092504&sr=8-1&keywords=Aldo+Derolphi\">Derolphi, SALE $42.99 (Originally $60)</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">14</span><span class=\"listicle__title\">Neiman Marcus</span></h2></p>\n\n"
"<p> </p>\n\n"
"<p><a href=\"http://www.lastcall.com/Neiman-Marcus-Classic-Quilted-Faux-Leather-Backpack-Cobalt/prod38910026/p.prod?eVar4=You%20May%20Also%20Like\">Classic Quilted Faux-Leather Backpack, Cobalt, SALE $31.50 (Orginally $135)</a></p>\n\n"
"<p><h2 class=\"listicle\"><span class=\"listicle__number\">15</span><span class=\"listicle__title\">Express</span></h2></p>\n\n"
"<p><a href=\"http://www.express.com/clothing/women/pebbled-tassel-backpack/pro/09804025/cat740011?AID=11388515&PID=2178999&SID=2238757044&CID=550&pubname=ShopStyle.com&pubID=2178999\">Pebbled Tassel Backpack, SALE $34.95 (Originally $59.90)</a></p>\n\n"
"<p><strong><em>Most Wanted</em></strong><em> is Bravo’s home for the most coveted clothing, beauty, gadgets, and home")
matches = re.finditer(regex, test_str)
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