On Wednesday, August 6, 2003, 7:42:01 PM, Robert wrote:

> Maybe a Regexp reuses the same MatchData instance through all matches
> (this saves instantiations).  If that were the case it would not make much
> sense marshalling a MatchData instance.  Instead one should probably
> convert it into an array.

I didn't really want to store them, I was just mucking around, so I'm
not going to argue on practical grounds.  However, Matchdata offer
useful properties: the string that was searched, the pre- and
post-matches.

I imagine there is some optimisation going on behind the scenes:
MatchData#string returns a frozen String, so it can certainly be
shared among many MatchData objects.  #pre_match appears to return a
copy of the pre-match, as modifiying its return value does not affect
subsequent calls.

All academic, anyway...

Gavin