From: Tom Pollard Date: 2007-01-30T03:24:40+09:00 Subject: Named groups in regexp matches? Hi, Does Ruby support regexps that assign names to specific matched groups? In Python, for instance, if you write a regexp like this, TEMP_RE = re.compile(r"""^(?P(M|-)?\d+|//|XX|MM)/ (?P(M|-)?\d+|//|XX|MM)?\s+""", re.VERBOSE) the match object will provide a hash with keys 'temp' and 'dewpt', containing the values matched by the corresponding '(?P...). and '(?P...)' groups. This is another solution to the problem of creating regexps where you want to parentheses both for grouping and substring capture. I know Perl and Ruby support the '(?:...)' syntax to let you use parens for specifying alternatives without capturing that group, but the Python scheme for labeling capture groups produces more readable code, and I've used it heavily in some code I was hoping to port to Ruby. I was hoping that perhaps I'd just overlooked something in the Ruby docs. Thanks, Tom