From: Pawel Szymczykowski Date: 2006-04-23T21:28:49+09:00 Subject: Re: Scan-like Idiom to Capture a Group as a String Instead of an Array? On 4/23/06, clc 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