Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think an HTML parser and a bit of XPath would be a better call than a regex. Something like this:</p> <pre><code>shipping = '//td[normalize-space(text())="shipping:"]/following-sibling::td[normalize-space(text())]' total = '//td[normalize-space(text())="TOTAL:"]/following-sibling::td[normalize-space(text())]' doc = Nokogiri::HTML &lt;&lt;HTML &lt;tr style='text-align:right;'&gt; &lt;td&gt; shipping: &lt;/td&gt; &lt;td style='padding-left:3em;'&gt;$17.00&lt;/td&gt; &lt;/tr&gt; &lt;tr style='text-align:right;'&gt; &lt;td&gt;TOTAL:&lt;/td&gt; &lt;td style='padding-left:3em;'&gt;$19.00&lt;/td&gt; &lt;/tr&gt; HTML has_shipping = doc.xpath(shipping).count == 1 # true has_total = doc.xpath(total ).count == 1 # true </code></pre> <p>But without the <code>$17.00</code> and <code>$19.00</code>:</p> <pre><code>doc = Nokogiri::HTML &lt;&lt;HTML &lt;tr style='text-align:right;'&gt; &lt;td&gt; shipping: &lt;/td&gt; &lt;td style='padding-left:3em;'&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr style='text-align:right;'&gt; &lt;td&gt;TOTAL:&lt;/td&gt; &lt;td style='padding-left:3em;'&gt;&lt;/td&gt; &lt;/tr&gt; HTML has_shipping = doc.xpath(shipping).count == 1 # false has_total = doc.xpath(total ).count == 1 # false </code></pre> <p>If you want to verify the format of the price as well then you can find just the <code>&lt;td&gt;</code>s you want and apply whatever Enumerable methods make sense in your situation:</p> <pre><code>shipping = '//td[normalize-space(text())="shipping:"]/following-sibling::td' good_one = doc.xpath(shipping).count { |n| n.content =~ /\A\s*\$\d+\.\d{2}\s*\z/ } == 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload