[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

gsub HELP

Newb Newb

8/23/2008 4:53:00 AM

Hi all
I am not Expert at Rails or Ruby
I have a string ..it contains text and images also..
from that string i want to replace the images into empty space..that
is images Has to Be Removed.
I tried to solve By using string.gsub..But doesn't Work
I tried like below

item.description = item.description.gsub("img src ",'')
So any guru can give Me solution...
--
Posted via http://www.ruby-....

4 Answers

Newb Newb

8/23/2008 7:06:00 AM

0

Newb Newb wrote:
> Hi all
> I am not Expert at Rails or Ruby
> I have a string ..it contains text and images also..
> from that string i want to replace the All The Images Into
> Empty>space..that is images Has to Be Removed.
>
> I tried like below
>
> item.description = item.description.gsub(/\<*img.*src=".*".*?\/\>/,' ')

> Using This Regular Expression I can able to Reomve Only The First
> Occurrences of The Images,But I Need TO Remove All Occurences Of The Images



> So Any Guru Can give Me solution...

--
Posted via http://www.ruby-....

Robert Dober

8/23/2008 9:06:00 AM

0

On Sat, Aug 23, 2008 at 9:06 AM, Newb Newb <hema@angleritech.com> wrote:
> Newb Newb wrote:
>> Hi all
>> I am not Expert at Rails or Ruby
>> I have a string ..it contains text and images also..
>> from that string i want to replace the All The Images Into
>> Empty>space..that is images Has to Be Removed.
>>
>> I tried like below
>>
>> item.description = item.description.gsub(/\<*img.*src=".*".*?\/\>/,' ')
The . stays for any character, as such your regular expression seems
to be way too greedy.
This however should not harm too much if there is only one img tag in
one line, although backtracking
might be a performance issue. I do however fail to understand the
behavior you described.
Anyway, I believe the following regex should do fine:

item.description.gsub! /<img.*?>/, ""

HTH
Robert


--
http://ruby-smalltalk.blo...

There's no one thing that's true. It's all true.
--
Ernest Hemingway

Newb Newb

8/23/2008 9:43:00 AM

0


> The . stays for any character, as such your regular expression seems
> to be way too greedy.
> This however should not harm too much if there is only one img tag in
> one line, although backtracking
> might be a performance issue. I do however fail to understand the
> behavior you described.
> Anyway, I believe the following regex should do fine:
>
> item.description.gsub! /<img.*?>/, ""
>
> HTH
> Robert
>
>
> --
> http://ruby-smalltalk.blo...
>
> There's no one thing that's true. It's all true.

thanks a lot
it works
--
Posted via http://www.ruby-....

Phlip

8/23/2008 2:11:00 PM

0

>> item.description = item.description.gsub(/\<*img.*src=".*".*?\/\>/,' ')
>
>> Using This Regular Expression I can able to Reomve Only The First
>> Occurrences of The Images,But I Need TO Remove All Occurences Of The Images

How did you do with the >10 replies you got before? Did Hpricot work out?