On 4/12/06, joe <allenbobo@gmail.com> wrote:> Hi all
> Which is the fastest way to gsub a 5000 char string.
> i.e.
> big_string = "i am so
<script>..3000char...</script>big<noscript>...2000
> char...</noscript> gsub me!!!"
> # If i run:
> big_string.gsub(/<script(.|\s)*<\/script>/i, ''
'').gsub(/<noscript>/, ''
> '').gsub(/</noscript>/, '' '')
>
> "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
</noscript> 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(/<noscript>/, ''
'').gsub(/<\/noscript>/, '' '')
-- James