On Tue, 28 Mar 2006, Geoff wrote: > Is there a way to concatenate regular expressions in ruby? Something > like Regexp.union but without the or between expressions. > > For example say i have the following regular expressions: > > Set = /[\[][1-9][\d][\]]/ > Field = /[F][S]?[1-9][\d]*/ > > and i want to make a regular expression to match both of them, i'd like > to be able to do something like the following: > > SetThenField = Set + /([\s])*/ + Field + /[\s]/ > > - Geoff you could do (untested) def re_union *res Regexp::new res.flatten.map{|re| re.source}.join end regards. -a -- share your knowledge. it's a way to achieve immortality. - h.h. the 14th dali lama