From: Brian Candler Date: 2009-04-08T22:23:14+09:00 Subject: Re: Concatenating Regex Smartly Shak Shak wrote: > \A\d+\Z and \A[a-z]+\Z These are two regular expressions both anchored to the start and end of the string. If you want to match one or the other: re1 = /\A\d+\z/ re2 = /\A[a-z]+\z/ re3 = /#{re1}|#{re2}/ => /(?-mix:\A\d+\z)|(?-mix:\A[a-z]+\z)/ But to "concatenate" in the sense of making a regexp which matches digits followed by letters, you need to remove the anchors. re1 = /\d+/ re2 = /[a-z]+/ re3 = /\A#{re1}#{re2}\z/ => /\A(?-mix:\d+)(?-mix:[a-z]+)\z/ Note that #{re1} and #{re2} are each surrounded by a non-capturing group (?...) when they are interpolated into re3. So it should also work properly for more complex REs, e.g. re1 = /a|b/ re2 = /c|d/ re3 = /\A#{re1}#{re2}\z/ But if you want to be extra-certain that it's done correctly, you can always add your own additional layer of grouping: re3 = /\A(?:#{re1}#{re2})\z/ -- Posted via http://www.ruby-forum.com/.