From: Mike Stok Date: 2002-09-24T02:58:56+09:00 Subject: Re: another easy one... In article <5.1.0.14.2.20020923113822.00b0cea8@zcard04k.ca.nortel.com>, Mark Probert wrote: > > My brain just isn't working this morn... > > Say, ch is a character and I want to find if it > exists in a regexp /A-Za-z0-9_/. How do I do it? > > irb> c.include?(/A-Za-z0-9_/) > "TypeError: cannot convert Regexp into String" > > I can do: > > irb> c.count("A-Za-z0-9_") > 1 > > And look for a 0 being a non-match. Is c a one character string? If so you can say %w(a ^ x).each { |c| puts "#{c} matches" if c =~ /[A-Za-z0-9_]/ # /\w/ maybe puts "#{c} matches" if c.count("A-Za-z0-9_").nonzero? } Hope this helps, (and that I haven't missed your point :-) Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA