# Html parser with regex, how to solve?

**URL:** <https://www.ruby-forum.com/t/html-parser-with-regex-how-to-solve/125137>\
**Category:** Ruby\
**Created:** [January 6, 2008, 1:07am UTC](https://www.ruby-forum.com/t/html-parser-with-regex-how-to-solve/125137 "2008-01-06T01:07:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [January 6, 2008, 1:07am UTC](https://www.ruby-forum.com/t/html-parser-with-regex-how-to-solve/125137/1 "2008-01-06T01:07:43Z")

</div>

Yeah,

I`m trying to develop a simple application using ruby (when this works i  
will pass to rails). I need get the source code from a URL, and find for  
this string:

### $299.99

wow, but i need search for not only 149.00, but for all possible  
numbers, my  
friend suggest this:

### \*$\d+\.\d{2}.\*

i think this works! but i need other thing… look my code:

#!/usr/bin/ruby

require ‘hpricot’  
require ‘open-uri’

@content = Hpricot(open("  
[http://www.newegg.com/Product/Product.aspx?Item=N82E16855101066](http://www.newegg.com/Product/Product.aspx?Item=N82E16855101066)"))

now how i can find for

### _$\d+.\d{2}._
 ?

@content.search(“

### _$\d+.\d{2}._
”) is broken ;(

how i can solved this?

thanks for you attention,  
Luiz Vitor Martinez C…

–  
Regards,  
Luiz Vitor Martinez C. [Grabber].  
(11) 8187-8662

[rubz.org](http://rubz.org) - engineer student at maua.br

---

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [January 6, 2008, 2:36am UTC](https://www.ruby-forum.com/t/html-parser-with-regex-how-to-solve/125137/2 "2008-01-06T02:36:40Z")

</div>

Thanks much! This really works 😉

Now i`m having a new problem (very simple), the output is $1999,00, how  
i  
can remove a $? I will need convert this to a float number 😉

Regards,  
Luiz Vitor Martinez C…

On Jan 5, 2008 11:10 PM, s.ross [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Yeah,  
> > numbers, my
> > 
> > thanks for you attention,

–  
Regards,  
Luiz Vitor Martinez C. [Grabber].  
(11) 8187-8662

[rubz.org](http://rubz.org) - engineer student at maua.br

---

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [January 6, 2008, 3:16am UTC](https://www.ruby-forum.com/t/html-parser-with-regex-how-to-solve/125137/3 "2008-01-06T03:16:26Z")

</div>

try this:

ele.text.sub(’$’, ‘’)

Joe

---

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [January 6, 2008, 2:10am UTC](https://www.ruby-forum.com/t/html-parser-with-regex-how-to-solve/125137/4 "2008-01-06T02:10:56Z")

</div>

Don’t use the regex. Let hpricot do what it’s good at:

$ irb

> > require ‘rubygems’  
> > require ‘hpricot’  
> > html = ‘
> > 
> > ### 149.00
> > ’  
> > doc = Hpricot.parse(html)  
> > ele = doc.search(‘h3.zmp’)  
> > puts ele.text  
> > =\> 149.00

In your code, your @content will be searchable the same way. Hpricot  
will give you a collection of all h3’s with class ‘zmp’.

[http://code.whytheluckystiff.net/doc/hpricot/](http://code.whytheluckystiff.net/doc/hpricot/)

Hope this helps.

---

<div class="post-metadata">

**Author:** ![lz-coelho](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lz-coelho](https://www.ruby-forum.com/u/lz-coelho)\
**Post date:** [January 6, 2008, 3:33am UTC](https://www.ruby-forum.com/t/html-parser-with-regex-how-to-solve/125137/5 "2008-01-06T03:33:25Z")

</div>

Thanks

I do it!

Regards,  
Luiz Vitor Martinez C…

On Jan 6, 2008 12:15 AM, Joe [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Now i`m having a new problem (very simple), the output is $1999,00, how
> > 
> > > will give you a collection of all h3’s with class ‘zmp’.
> > > 
> > > > I`m trying to develop a simple application using ruby (when this
> > > > 
> > > > [http://www.newegg.com/Product/Product.aspx?Item=N82E16855101066](http://www.newegg.com/Product/Product.aspx?Item=N82E16855101066)"))

–  
Regards,  
Luiz Vitor Martinez C. [Grabber].  
(11) 8187-8662

[rubz.org](http://rubz.org) - engineer student at maua.br
