I am using Ruby 1.9.2p320 and running the following code snippet:
a = ["abc", "def", "pqr", "xyz"]
z = ["abc", "xyz"]
a.grep(/#{z}/)
That gives this output: ["abc", "xyz"].
a = ["abc_1", "def_1", "pqr_1", "xyz_1"]
z = ["abc_1", "xyz_1"]
a.grep(/#{z}/)
But this gives output as: ["abc_1", "def_1", "pqr_1", "xyz_1"].
What I expected was just ["abc_1", "xyz_1"].
Any particular reason why am i getting that output? And how could I get the expected output?