# Help me

**URL:** <https://www.ruby-forum.com/t/help-me/110116>\
**Category:** Ruby\
**Created:** [July 23, 2007, 1:41pm UTC](https://www.ruby-forum.com/t/help-me/110116 "2007-07-23T13:41:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![geetha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f08c70/32.png) [@geetha](https://www.ruby-forum.com/u/geetha)\
**Post date:** [July 23, 2007, 1:41pm UTC](https://www.ruby-forum.com/t/help-me/110116/1 "2007-07-23T13:41:21Z")

</div>

Hi,  
I am doing string search is one html file usign ruby.  
If the seach sting is htmlentities means I have not match that word.  
How can i do it. Please any one help me…

regards,  
S.Sangeetha.

---

<div class="post-metadata">

**Author:** ![geetha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f08c70/32.png) [@geetha](https://www.ruby-forum.com/u/geetha)\
**Post date:** [July 23, 2007, 1:56pm UTC](https://www.ruby-forum.com/t/help-me/110116/2 "2007-07-23T13:56:00Z")

</div>

On 7/23/07, geetha [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,  
> I am doing string search is one html file usign ruby.  
> If the seach sting is htmlentities means I have not match that word.  
> How can i do it. Please any one help me…
> 
> regards,  
> S.Sangeetha.

We might be able to help you better if you post the data and what you  
expect to get out from it exactly.

Robert

---

<div class="post-metadata">

**Author:** ![geetha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f08c70/32.png) [@geetha](https://www.ruby-forum.com/u/geetha)\
**Post date:** [July 23, 2007, 2:32pm UTC](https://www.ruby-forum.com/t/help-me/110116/3 "2007-07-23T14:32:43Z")

</div>

On 7/23/07, Robert D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> expect to get out from it exactly.
> 
> Robert
> 
> –

Robert:  
If search string has html entities, then do not proceed with search.

Well, its very hard to define if query string has HTML entities or  
not? For example, do you consider following string has HTML entities?

b = “hello world and so what; and \< and there we go \>”

dunno yes and no, but if your answer is yes, and string `b` HAS HTML  
entities then:

require ‘cgi’

escaped\_html = CGI::escapeHTML(b)  
if escaped\_html != b

# string contains html entities

end

if you want a strict validation of HTML tags, and whether query is a  
valid HTML, then hpricot may help.

–  
Let them talk of their oriental summer climes of everlasting  
conservatories; give me the privilege of making my own summer with my  
own coals.

[http://blog.gnufied.org](http://blog.gnufied.org)

---

<div class="post-metadata">

**Author:** ![geetha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f08c70/32.png) [@geetha](https://www.ruby-forum.com/u/geetha)\
**Post date:** [July 23, 2007, 2:52pm UTC](https://www.ruby-forum.com/t/help-me/110116/4 "2007-07-23T14:52:40Z")

</div>

On 7/23/07, hemant [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > We might be able to help you better if you post the data and what you  
> > not? For example, do you consider following string has HTML entities?
> 
> # string contains html entities
> 
> end
> 
> if you want a strict validation of HTML tags, and whether query is a  
> valid HTML, then hpricot may help.

Some tips on asking questions:

1. Have a meaningful subject or else your question will look like spam.
2. Also please respond to answers that people are posting in response  
to your question.
3. Robert suggestions.

–  
Let them talk of their oriental summer climes of everlasting  
conservatories; give me the privilege of making my own summer with my  
own coals.

[http://blog.gnufied.org](http://blog.gnufied.org)

---

<div class="post-metadata">

**Author:** ![geetha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f08c70/32.png) [@geetha](https://www.ruby-forum.com/u/geetha)\
**Post date:** [July 23, 2007, 4:12pm UTC](https://www.ruby-forum.com/t/help-me/110116/5 "2007-07-23T16:12:47Z")

</div>

On 7/23/07, Alex Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > >
> > 
> > Well, its very hard to define if query string has HTML entities or  
> > not?  
> > No it’s not…

Honestly, its up to user. Unless we are talking about valid XHTML,  
which is definitely defined.

> irb(main):002:0\> re = REXML::Text::REFERENCE

I thought about this, when I was posting that response, but somehow i  
felt user is not looking for valid HTML, but just if it contains HTML  
entities or not?

---

<div class="post-metadata">

**Author:** ![geetha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f08c70/32.png) [@geetha](https://www.ruby-forum.com/u/geetha)\
**Post date:** [July 25, 2007, 5:02pm UTC](https://www.ruby-forum.com/t/help-me/110116/6 "2007-07-25T17:02:37Z")

</div>

Hpricot is certainly one tool you should consider.  
also Rexml and Scrubyt.  
Scrubyt is more for web-scraping but if you can scrape it, you can  
remove it too.

---

<div class="post-metadata">

**Author:** ![geetha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/f08c70/32.png) [@geetha](https://www.ruby-forum.com/u/geetha)\
**Post date:** [July 23, 2007, 3:53pm UTC](https://www.ruby-forum.com/t/help-me/110116/7 "2007-07-23T15:53:42Z")

</div>

hemant wrote:

> > We might be able to help you better if you post the data and what you  
> > not?  
> > No it’s not…

> For example, do you consider following string has HTML entities?
> 
> b = “hello world and so what; and \< and there we go \>”
> 
> dunno yes and no, but if your answer is yes,  
> Then you’d be wrong.

irb(main):001:0\> require ‘rexml/text’  
=\> true  
irb(main):002:0\> re = REXML::Text::REFERENCE  
=\> /(?:&([\w:][-\w\d.:]\*);|&#\d+;|&#x[0-9a-fA-F]+;)/  
irb(main):003:0\> “this & that” =~ re  
=\> 5  
irb(main):004:0\> “hello world and so what; and \< and there we go \>” =~  
re  
=\> nil

Admittedly I’m not scanning for all defined HTML entities, just for  
valid XML entities, but given that one’s a superset of the other, and  
undefined entity references probably shouldn’t occur within a valid HTML  
document anyway, it’s good enough for most purposes…
