On Wed, 25 Jun 2003 15:27:06 +0900
"Rob" <robson / magario.com> wrote:


> What I am trying to do is that everytime the program finds one of the words
> from the list in the text,
> it will place an astherisc * to replace that word.
> 
> But I cannot figure out how to do this because it is an array not a regular
> expression.

Short way:

    array.each { |w| s.gsub!(w, "*") }

Longer, possibly more efficient way:

    re = array.join('|')
    s.gsub!(/(#{re})/, "*")

The second way is probably more efficient, since it can optimize the
match and do it in one pass.

HTH,

-- 
Ryan Pavlik <rpav / users.sf.net>

"And I'm 10,000 feet up in the air. Dang it." - 8BT