On 4/23/06, clc <clc1024 / hotmail.com> wrote:
> I've been using these two lines to capture text that only appears once, but
> the second line bothers me a little.  Is there a one-line idiom for this
> that extracts groups like #scan but returns a string instead of an array so
> the second line isn't needed?
>
> text = string.scan( %r{ skip_this ( keep_this ) skip_this }is )
> text = text[ 0 ]

Any reason why

text = string.scan( %r{ skip_this ( keep_this ) skip_this }is ).first

or

text = string.scan( %r{ skip_this ( keep_this ) skip_this }is )[0]

wouldn't work?

-Pawel