From: Robert Klemme Date: 2006-04-24T21:12:57+09:00 Subject: Re: Scan-like Idiom to Capture a Group as a String Instead of an Array? 2006/4/23, clc : > 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 ] Adding to all the other replies: keep in mind that scan usually returns multiple results which implies that you want to process all of them. If you know that there will be only one match of this in your string or if you only want to work with the first match, I suggest to use =~ or String[%r{ skip_this ( keep_this ) skip_this }is, 1] as Yoann showed. Kind regards robert -- Have a look: http://www.flickr.com/photos/fussel-foto/