>>>>> "H" == Horacio Sanson <hsanson / moegi.waseda.jp> writes: H> Regexp.new("#{key1}\.*#{key2}|#{key2}\.*#{key1}") vs H> r1 = Regexp.new("#{key1}\.*#{key2}") H> r2 = Regexp.new("#{key2}\.*#{key1}") H> Is this expected when using regular expressions?? yes, ruby has some optimizations. For example with the regexp /abc.*def/ svg% ruby -rjj -e '/abc.*def/.dump' Regexp /abc.*def/ 0 exactn "abc" (3) 1 anychar_repeat 2 exactn "def" (3) 3 end must : abc optimize : exactn svg% It call the regexp engine (which is slow) only when it has found the substring "abc" in the string Now if you use /abc.*def|def.*abc/ you break this optimization svg% ruby -rjj -e '/abc.*def|def.*abc/.dump' Regexp /abc.*def|def.*abc/ 0 on_failure_jump ==> 5 1 exactn "abc" (3) 2 anychar_repeat 3 exactn "def" (3) 4 jump ==> 8 5 exactn "def" (3) 6 anychar_repeat 7 exactn "abc" (3) 8 end svg% it must call the stupid (:-)) regexp engine for each line Guy Decoux