From: Trans Date: 2005-04-21T01:04:35+09:00 Subject: Linear complete variation of MatchData#to_a, possible? Hi-- I have a it bit of a puzzle for Regexp engine hackers out there. The #to_a method on MatchData gives a simple list of matching portions of the matched text. md = /(1)(2(3))(4)/.match "012345" md.to_a ["1234", "1", "23", "3", "4"] But I would like a method the produces a linearly segmented list of the text itself, like this: ["0", "1", "2", [ "3" ], "4", "5" ] Notice the array depth corresponds to the subexpression depth. My first stab was: def matchlist # good idea to cache? @matchset ||= pre_match + self[1..-1] + post_match end But obviously that does not work when there are subexpressions. Is such a method even possible? Thanks, T.