Q:

Python Regex - Not Printing Values Expected

I'm trying to get my regular expression to spit out the price of an item only from an XML file.  This is what I currently have, however it prints the entire text.  I'm only wanting for it to print out the price ($95).  What am I doing wrong? 
This is my regex: <span class="price" id="product-price-[0-9]*">\$([0-9]*?\.[0-9]*)
Code:
from re import findall

text = '''This XML file does not appear to have any style information associated with it.  The document tree is shown below. 
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
<channel>
<title>
<![ CDATA[ New Products from Main Website Store ]]>
</title>
<link>
http://www.joomlajingle.com/rss/catalog/new/store_id/1/
</link>
<description>
<![ CDATA[ New Products from Main Website Store ]]>
</description>
<pubDate>Fri, 19 May 2017 12:07:04 +0000</pubDate>
<generator>Zend_Feed</generator>
<language>en_US</language>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<item>
<title>
<![ CDATA[ Womens Free People White Textured Lace Mini Dress ]]>
</title>
<link>
http://www.joomlajingle.com/womens-free-people-white-textured-lace-mini-dress.html
</link>
<description>
<![ CDATA[
<table><tr><td><a href="http://www.joomlajingle.com/womens-free-people-white-textured-lace-mini-dress.html"><img src="http://www.joomlajingle.com/media/catalog/product/cache/1/thumbnail/75x75/9df78eab33525d08d6e5fb8d27136e95/3/9/39247291_010_a.jpg" border="0" align="left" height="75" width="75"></a>
]]>
<![ CDATA[
</td><td style="text-decoration:none;"><strong>Womens Free People White Textured Lace Mini Dress</strong>Allover lace mini dress featuring a swing skirt, cutout detailing along the waist and contrast lace along the neckline and shoulders.  Grosgrain ribbon trim and adjustable ties on the wide sleeve cuff.  Hidden back zip.  Lined. For Love & LemonsDerived from those sun-soaked "Lemonade Stand Days," designers, owners, and BFF's Gillian Mahin and Laura Hall are the masterminds behind For Love & Lemons.  Based in Los Angeles, the collection is anything but conventional.  For Love & Lemons is a brand for that girl who doesn't follow trends, she makes them.<ul class="content-bullets"><li>95% Cotton</li><li>5% Nylon</li><li>Contrast: 57.2% Nylon, 27.3% Polyester</li><li>Contrast 2: 72% Nylon, 18% Cotton, 10% Rayon</li><li>Lining: 97% Polyester, 3% Spandex</li></ul><ul class="content-bullets product-care"><li>Dry Clean</li></ul><ul class="content-bullets"><li>Import</li></ul> <div class="price-box"> <p class="old-price"> <span class="price-label">Regular Price:</span> <span class="price" id="old-price-5937">$255.00</span> </p> <p class="special-price"> <span class="price-label">Special Price:</span> <span class="price" id="product-price-5937">$95.00</span> </p> </div> </td></tr></table>
]]>
</description>
<pubDate>Fri, 19 May 2017 12:07:04 +0000</pubDate>
</item>
'''

find_price = ('<span class="price" id="product-price-[0-9]*">\$([0-9]*?\.[0-9]*)', text)
print find_price

forgot the findall...

A:

You probable don't want to use regexp to do xml parsing.  You better use a robust xml parser, for example BeautifulSoup 
See the following example code
soup = BeautifulSoup(text)
import re

find_price = None

for cd in soup.findAll(text=True):
  if isinstance(cd, CData):
      s = BeautifulSoup(cd)
      prices = s('span', {'class': 'price'})
      for price in prices:
          if price.has_key('id') and re.match('product-price-\d+', price['id']):
              find_price = price.text
              break

print find_price

Which gives the result you want:
$ python test.py 
$95.00

