[Solved] How do I extract the characters in between the specific set of characters in a string python(regex)? [closed]


import re

txt = """div><div class="ShLswe"><a class="_2WFi0x" href="https://stackoverflow.com/order_details?order_id=OD40818094004&amp;item_id=OD408180940040000&amp;unit_id=OD408180940040000000"><div class="row"><div class="col-6-12"><div class="row"><div class="col-3-12"><div class="J2h1WZ"><div class="_3BTv9X" style="height: 75px; width: 75px;"><img class="_1Nyybr  _30XEf0" alt="" src="https://rukminim1.flixcart.com/image/75/75/usb-adaptor/s/9/8/tp-link-150-mbps-wireless-n-original-imad8rruefj6rf3y.jpeg"></div></div></div><div class="col-8-12"><div class="_3D-3p2"><span class="row _13y4_y _1iu0PI">TP-LINK 150 Mbps TL-WN721N Wireless N</span><div class="row _3i00zY"><span class="_3i00zY _2n1WrW">Seller: </span><span class="_2dTbPB">WS Retail</span></div></div></div></div></div><div class="col-2-12 JL36Xz">₹512</div><div class="col-4-12 _3Yi3bU"><div><div class="_30ud5x _3ELbo9"></div><span class="_7BRRQk">Delivered on Aug 20, 2014</span><div class="_2t-3dH">Your item has been delivered</div></div><div class="d-uGDa"></div><div class="paz6BF"><div class="_1S3Y5S row"><a class="FlPMmo"><img src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0nMTYnIGhlaWdodD0nMTknIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2aWV3Qm94PSIwIDAgMTggMTgiPgoJPGcgZmlsbD0nbm9uZSc+CgkJPHBvbHlnb24gaWQ9IlNoYXBlIiBmaWxsPSIjMjg3NEYxIiBwb2ludHM9IjkgMTIuMDYyNSAxMy42Mzc1IDE1LjQzNzUgMTEuODYyNSA5Ljk4NzUgMTYuNSA2LjY4NzUgMTAuODEyNSA2LjY4NzUgOSAxLjA2MjUgNy4xODc1IDYuNjg3NSAxLjUgNi42ODc1IDYuMTM3NSA5Ljk4NzUgNC4zNjI1IDE1LjQzNzUiIC8+CgkJPHBvbHlnb24gaWQ9IlNoYXBlIiBwb2ludHM9IjAgMCAxOCAwIDE4IDE4IDAgMTgiIC8+Cgk8L2c+Cjwvc3ZnPg==" class="_3Q4GqT col-1-5"><span class="_3zvrLw col-3-5">Rate &amp; Review Product</span></a></div></div></div></div></a></div></div>"<"""


regex = re.compile(r"<img class=\"_1Nyybr  _30XEf0\" alt=\"\" src=\"(?P<image>.+?)\.jpeg.*<span class=\"row _13y4_y _1iu0PI\">(?P<name>.+?)</span>.*<div class=\"col-2-12 JL36Xz\">\D*(?P<cost>\d+?)</div>")

result = regex.search(txt)
print(result.group("image"))
print(result.group("name"))
print(result.group("cost"))

The output is:

https://rukminim1.flixcart.com/image/75/75/usb-adaptor/s/9/8/tp-link-150-mbps-wireless-n-original-imad8rruefj6rf3y
TP-LINK 150 Mbps TL-WN721N Wireless N
512

solved How do I extract the characters in between the specific set of characters in a string python(regex)? [closed]