# Extract a number from a line of HTML file

**URL:** <https://www.ruby-forum.com/t/extract-a-number-from-a-line-of-html-file/111898>\
**Category:** Ruby\
**Created:** [August 13, 2007, 5:43am UTC](https://www.ruby-forum.com/t/extract-a-number-from-a-line-of-html-file/111898 "2007-08-13T05:43:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ak756](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b5a626/32.png) [@ak756](https://www.ruby-forum.com/u/ak756)\
**Post date:** [August 13, 2007, 5:43am UTC](https://www.ruby-forum.com/t/extract-a-number-from-a-line-of-html-file/111898/1 "2007-08-13T05:43:03Z")

</div>

Hi,

I have a line of HTML file like this

**123.20**

I want to remove all such HTML tags as ‘’ and only get the 123.20.

Would anyone kindly tell me how?

Thanks very much.

---

<div class="post-metadata">

**Author:** ![ak756](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b5a626/32.png) [@ak756](https://www.ruby-forum.com/u/ak756)\
**Post date:** [August 13, 2007, 6:18am UTC](https://www.ruby-forum.com/t/extract-a-number-from-a-line-of-html-file/111898/2 "2007-08-13T06:18:04Z")

</div>

On 8/13/07, Ak 756 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## Thanks very much.
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Your going to need to give some more information here. Using  
javascript?  
On the server side? Is it always that format?

---

<div class="post-metadata">

**Author:** ![ak756](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b5a626/32.png) [@ak756](https://www.ruby-forum.com/u/ak756)\
**Post date:** [August 13, 2007, 6:27am UTC](https://www.ruby-forum.com/t/extract-a-number-from-a-line-of-html-file/111898/3 "2007-08-13T06:27:17Z")

</div>

Daniel ----- wrote:

> On 8/13/07, Ak 756 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > ## Thanks very much.
> > 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> Your going to need to give some more information here. Using  
> javascript?  
> On the server side? Is it always that format?

Hi Daniel

I got this line from the body of NET::HTTP.post\_form. I want to extract  
the digital number embedded in this line. Actually ,I think I can do  
this by remove all strings begin with “\<” and end with “\>”. But I don’t  
know how to do.

---

<div class="post-metadata">

**Author:** ![ak756](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b5a626/32.png) [@ak756](https://www.ruby-forum.com/u/ak756)\
**Post date:** [August 13, 2007, 6:40am UTC](https://www.ruby-forum.com/t/extract-a-number-from-a-line-of-html-file/111898/4 "2007-08-13T06:40:05Z")

</div>

On 8/13/07, Ak 756 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > javascript?  
> > On the server side? Is it always that format?
> 
> Hi Daniel
> 
> I got this line from the body of NET::HTTP.post\_form. I want to extract  
> the digital number embedded in this line. Actually ,I think I can do  
> this by remove all strings begin with “\<” and end with “\>”. But I don’t  
> know how to do.

So server side… If you use the Hpricot Gem you can do this pretty  
easy.

a = “ **123.20** ”  
value = Hpricot( a ).innerText.strip

HTH  
Daniel

---

<div class="post-metadata">

**Author:** ![ak756](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b5a626/32.png) [@ak756](https://www.ruby-forum.com/u/ak756)\
**Post date:** [August 13, 2007, 7:08am UTC](https://www.ruby-forum.com/t/extract-a-number-from-a-line-of-html-file/111898/5 "2007-08-13T07:08:42Z")

</div>

Daniel ----- wrote:

> So server side… If you use the Hpricot Gem you can do this pretty  
> easy.
> 
> a = “
> 
> **123.20** ”  
> value = Hpricot( a ).innerText.strip
> 
> HTH  
> Daniel

Hi Daniel

Thanks! Great gem! It’s exactly what I want, and so simply!  
Thanks very much.

ak756
