Hi -- 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]*/ You don't need character classes for single characters: Set = /\[[1-9]\d\]/ Field = /FS?[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]/ How about: SetThenField = /#{Set}(\s)*#{Field}\s/ (This is all untested but it might point you in a helpful direction.) David -- David A. Black (dblack / wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" chapters now available from Manning Early Access Program! http://www.manning.com/books/black