Check out MakeRegEx in RAA.  It will take any list of words and generate a
minimum RE to match all of them

----- Original Message -----
From: "William Djaja Tjokroaminata" <billtj / z.glue.umd.edu>
Newsgroups: comp.lang.ruby
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>; <undisclosed-recipients: ;>
Sent: Friday, October 19, 2001 10:26 AM
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
>