From: tamouse mailing lists Date: 2012-12-22T22:17:17+09:00 Subject: Re: A stupid question? n Fri, Dec 21, 2012 at 9:56 AM, Brian Candler wrote: > Al Baker wrote in post #1089770: >> I'm trying to find a way to count the consonants in a sentence. how >> would i go about that? i tried to use length - [aeiou]. but never got >> the result i was looking for > >>> str = 'Hello, world!?' >>> str.scan(/[a-df-hj-np-tv-z]/i).size > => 7 >>> str.gsub(/[^a-df-hj-np-tv-z]/i,'').size > => 7 (a is a vowel...) I'd suggest this: > s = 'Helloooo my wonderfuuuuul peeeopulllaaaa. IIII am come!!' => "Helloooo my wonderfuuuuul peeeopulllaaaa. IIII am come!!" > s.scan(/[^aeiou]+/i).join('') => "Hll my wndrfl pplll. m cm!!" > s.scan(/[^aeiou]+/i).join('').size => 28