From: William Djaja Tjokroaminata Date: 2001-10-20T02:26:10+09:00 Subject: [ruby-talk:22769] How to Convert String to Regex to Perform Exact Match Hi, Is there any easy way to convert a string str to a regexp reg so that the effect of reg = str.to_regexp another_str =~ reg is exactly the same as another_str == str I could not find a function that performs the "to_regexp" utility. Although it is true that for a single argument I can just check the type such as def match (str) ..... if str.type == String if another_str == str ..... elsif str.type == Regexp if another_str =~ str ..... end this will become clumsy (and probably slow) if I have multiple arguments and I have a loop inside the function. So basically before I execute the loop in the function, I want to convert each argument, if it is of type String, to a Regexp that performs an exact match. Therefore inside the loop I don't have to check whether any argument is String or Regexp; I just perform exact matching based on Regexp. Thanks. Regards, Bill