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
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!!!”
big_string.gsub(/<script(.|\s)*</script>/i, ’ ').gsub(//, ’
').gsub(//, ’ ')
“cpu 99% and stuck there”
regrads
On 4/12/06, joe [email protected] 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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs