[ruby-talk:00827] Re: feature request

From: OZAWA Sakuro <crouton@...>
Date: 1999-09-29 03:01:18 UTC
List: ruby-talk #827
At Tue, 28 Sep 1999 22:55:52 -0400,
Jonathan Aseltine <aseltine@cs.umass.edu> wrote:

> x = "a.b c.d"
> x.gsub!(/(\w).(\w)/) {|i, j| <do something with the matched
> subexpressions>}

> Right now, Ruby only gives the entire matched string to the block.

Try this:
	x.scan(/(\w)\.(\w)/) { |i| p i }

i holds Array of matched groups, so you can retrieve each group via
its indices.

-- 
--
OZAWA -Crouton- Sakuro
<mailto:crouton@duelists.org>
<http://www.duelists.org/~crouton/>



In This Thread