Hello --

On Sat, 21 Sep 2002, Johann Spies wrote:

> After playing a little bit with Ruby 3 years ago, I am trying to learn
> it now.
> Problem:
>
> a = ["aaa","abb","bbb","acc","bcc","ccc"]
>
> I want a regular expression which would extract something like ["acc",
> "ccc"] from a
>
> I want something like
>
> irb(main):023:0> for b in a
> irb(main):024:1> b.scan("#{(a||c)}cc") && print b
> irb(main):025:1> end
>
> but I am not sure how to approach it.

I would use #select, which filters based on a condition contained
in a code block:

  a = ["aaa","abb","bbb","acc","bcc","ccc"]
  puts a.select {|e| /(a|c)cc/.match(e)}

  =>
    acc
    ccc


David

-- 
David Alan Black                      | Register for RubyConf 2002!
home: dblack / candle.superlink.net     | November 1-3
work: blackdav / shu.edu                | Seattle, WA, USA
Web:  http://pirate.shu.edu/~blackdav | http://www.rubyconf.com