How to pull out number in string with python?
<p>I have a project where I pull out some posts of a subreddit (/r/buildapcsales) and email me with some deals.</p>

<p>For example: </p>

<ol>
<li>[Monitor] AOC 21.5" 1080p 75Hz 1ms FreeSync Monitor - <strong>$105</strong> ($229.99 - $110 sale - $15 promo thru 10/13)</li>
<li>[Monitor] EQD Auria EQ278CG 27 inch 144hz 1080p 3ms - <strong>$149.99</strong> (Newegg Flash)</li>
<li>[Monitor] EQD Auria EQ248CG 24 inch 144hz 1080p 3ms - <strong>$128.99</strong> (Newegg Flash)</li>
<li>[Monitor] Acer CB280HK 4k TN 1ms 60hz - <strong>$249.99</strong> ($449.99 - $200 Instant Rebate)</li>
<li>[Monitor] Acer K272HUL Ebmidpx 27â 2560 x 1440 1ms VESA Mountable - <strong>$239.99</strong> ($60 off)</li>
</ol>

<p>I want to pull out the bolded numbers and compare them to a threshhold (&lt;=200), but the problem is I cant use regex because that will pull out the calculations (i.e. $449.99 - $200 Instant Rebate) on the right also.</p>

<p>Is there another more clever way to do this? I'm completely lost.</p>

<blockquote>
  <p>I cant use regex because that will pull out the calculations (i.e. $449.99 - $200 Instant Rebate) on the right also.</p>
</blockquote>

<p>You can still use regular expressions and extract <em>the first amount coming after the dash</em>:</p>

<pre><code>import re

lines = [
    '1. [Monitor] AOC 21.5" 1080p 75Hz 1ms FreeSync Monitor - $105 ($229.99 - $110 sale - $15 promo thru 10/13)',
    '2. [Monitor] EQD Auria EQ278CG 27 inch 144hz 1080p 3ms - $149.99 (Newegg Flash)',
    '3. [Monitor] EQD Auria EQ248CG 24 inch 144hz 1080p 3ms - $128.99 (Newegg Flash)',
    '4. [Monitor] Acer CB280HK 4k TN 1ms 60hz - $249.99 ($449.99 - $200 Instant Rebate)',
    '5. [Monitor] Acer K272HUL Ebmidpx 27â 2560 x 1440 1ms VESA Mountable - $239.99 ($60 off)'
]

pattern = re.compile(r"- \$(\d+)")
for line in lines:
    print(pattern.search(line).group(1))
</code></pre>

<p>Prints:</p>

<pre><code>105
149
128
249
239
</code></pre>

python regex string reddit