From: GOTO Kentaro Date: 2002-09-24T03:23:31+09:00 Subject: Re: another easy one... At Tue, 24 Sep 2002 01:09:45 +0900, Mark Probert wrote: > My brain just isn't working this morn... Ask ri :) > 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" % ri 'String#include?' -------------------------------------------------------- String#include? str.include? aString -> true or false str.include? aFixnum -> true or false ------------------------------------------------------------------------ Returns true if str contains the given string or character. "hello".include? "lo" #=> true "hello".include? "ol" #=> false "hello".include? ?h #=> true % > I can do: > > irb> c.count("A-Za-z0-9_") > 1 > > And look for a 0 being a non-match. % ri String#count ----------------------------------------------------------- String#count str.count( [aString]+> ) -> aFixnum ------------------------------------------------------------------------ Each aString parameter defines a set of characters to count. The intersection of these sets defines the characters to count in str. Any aString that starts with a caret (^) is negated. The sequence c1--c2 means all characters between c1 and c2. a = "hello world" a.count "lo" #=> 5 a.count "lo", "o" #=> 2 a.count "hello", "^l" #=> 4 a.count "ej-m" #=> 4 %