"David Douthitt" <DDouthitt / cuna.com> writes:

> How do you translate this snippet:
> 
> ($var1, $var2, $var3) = /pattern (sub1) (sub2) (sub3)/;
> 
> I tried this:
> 
> var1 = (line =~ /pattern (sub1) (sub2) (sub3)/)
> 
> and it was syntactically successful but the contents of var1 were
> unexpected (zero).

A regular expression match returns the offset of the start of the
match. You can get the individual submatches by indexing the special
variable $~, or by using the Regexp.match method

   if line =~ /asdasd (\d+) (\d+) (\d+)/
      v1, v2, v3 = $~[1..-1]
   end

or

   v1, v2, v3 = /asasd (\d+) (\d+) (\d+)/.match(line)[1..-1]

However this latter form will fail if the match fails.

Regards


Dave