How to handle big string


#1

Hi all
Which is the fastest way to gsub a 5000 char string.
i.e.
big_string = “i am so big…2000
char… gsub me!!!”

If i run:

big_string.gsub(/<script(.|\s)*</script>/i, ’ ').gsub(//, ’
').gsub(//, ’ ')

“cpu 99% and stuck there”

regrads


#2

On 4/12/06, joe removed_email_address@domain.invalid wrote:

Hi all
Which is the fastest way to gsub a 5000 char string.
i.e.
big_string = “i am so big…2000
char… gsub me!!!”

If i run:

big_string.gsub(/<script(.|\s)*</script>/i, ’ ').gsub(//, ’
').gsub(//, ’ ')

“cpu 99% and stuck there”

This should take less than a second to excute, so you likely have
something else going wrong in your code.

Also, your regex is wrong. You aren’t escaping the / in the final
tag. That alternation you’re doing with the (.|\s)* can
be replaced by .*? and telling the regex to span multiple lines with
the ‘m’ option.

big_string.gsub(/<script.*?</script>/im, ’ ').gsub(//, ’
').gsub(/</noscript>/, ’ ')

– James