# Strinpping html using regexp

**URL:** <https://www.ruby-forum.com/t/strinpping-html-using-regexp/167215>\
**Category:** Ruby\
**Created:** [May 5, 2009, 4:38pm UTC](https://www.ruby-forum.com/t/strinpping-html-using-regexp/167215 "2009-05-05T16:38:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![arunvoip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e8c25b/32.png) [@arunvoip](https://www.ruby-forum.com/u/arunvoip)\
**Post date:** [May 5, 2009, 4:38pm UTC](https://www.ruby-forum.com/t/strinpping-html-using-regexp/167215/1 "2009-05-05T16:38:01Z")

</div>

Hi,  
I want to remove the all html tags in a string using regexp. But the  
main thing is I dont want to use gsub or any other methods for it. I  
want pure regexp to fetch the data other than the html tags. Can anybody  
please give me the code.

Thanks  
Arun

---

<div class="post-metadata">

**Author:** ![arunvoip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e8c25b/32.png) [@arunvoip](https://www.ruby-forum.com/u/arunvoip)\
**Post date:** [May 5, 2009, 4:51pm UTC](https://www.ruby-forum.com/t/strinpping-html-using-regexp/167215/2 "2009-05-05T16:51:15Z")

</div>

Arun K. wrote:

> Hi,  
> But the  
> main thing is I dont want to use gsub or any other methods for it.

In what programming language can you use a regex to find a match without  
calling a method?

---

<div class="post-metadata">

**Author:** ![arunvoip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e8c25b/32.png) [@arunvoip](https://www.ruby-forum.com/u/arunvoip)\
**Post date:** [May 5, 2009, 4:41pm UTC](https://www.ruby-forum.com/t/strinpping-html-using-regexp/167215/3 "2009-05-05T16:41:17Z")

</div>

Arun K. schrieb:

> Hi,  
> I want to remove the all html tags in a string using regexp. But the  
> main thing is I dont want to use gsub or any other methods for it. I  
> want pure regexp to fetch the data other than the html tags. Can anybody  
> please give me the code.
> 
> Thanks  
> Arun

1. regular expressions are not good for stripping html code, use a HTML  
Parser  
(Nokogiri, Hpricot, …)
2. if you want to use regexp, why not gsub? o\_O what do you mean by  
“pure  
regexp”? gsub can strip content based on regular expressions. I don’t  
get your  
point here.
3. …

---

<div class="post-metadata">

**Author:** ![arunvoip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e8c25b/32.png) [@arunvoip](https://www.ruby-forum.com/u/arunvoip)\
**Post date:** [May 5, 2009, 11:06pm UTC](https://www.ruby-forum.com/t/strinpping-html-using-regexp/167215/4 "2009-05-05T23:06:57Z")

</div>

On May 5, 10:38 am, Arun K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,  
> I want to remove the all html tags in a string using regexp.

No, you really really don’t. Trust me.

> I want pure regexp to fetch the data other than the html tags.

If you had said “pure XPath”, then that would make sense.

– Mark.

---

<div class="post-metadata">

**Author:** ![arunvoip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e8c25b/32.png) [@arunvoip](https://www.ruby-forum.com/u/arunvoip)\
**Post date:** [May 6, 2009, 12:15am UTC](https://www.ruby-forum.com/t/strinpping-html-using-regexp/167215/5 "2009-05-06T00:15:08Z")

</div>

Mark T. wrote:

> On May 5, 10:38ï¿½am, Arun K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hi,  
> > ï¿½ ï¿½I want to remove the all html tags in a string using regexp.
> 
> No, you really really don’t. Trust me.

Yes, yes, he really does. This is an ongoing line of questioning dating  
back several weeks.
