On Thursday, September 4, 2003, 12:04:47 PM, Jason wrote:

> this = "Dec 12"
> that, other = /(\w+) (\d+)/.match(this).captures
> p that, other

> ....but this will run into problems when there's not a match, and
> Regexp#match returns nil. So something like this might be better

> if m = /(\w+) (\d+)/.match(this)
>   that, other = m.captures
>   # Do stuff with "that" and "other"
> else
>   # We didn't match, do something about it
> end


Good point.  I'd probably use exception handling.

  that, other = REGEX.match(STR).captures rescue []

The two variables will receive nil if the match fails.  That's
slightly dodgy (may catch other exception?) but concise.  If you want
to handle it more explicitly, then

  begin
    that, other = REGEX.match(STR).captures
  rescue NoMethodError
    # handle it
  end

Gavin