ruby regular expressions

Started by
1 comment, last by HVA310 17 years ago
I have read over and over about regular expressions in ruby. All i want to do is count the occurrence of a specific pattern in a string. For instance, if i have a method where give the string and the pattern as parameters, it returns the count of instances of that pattern. I dont want to just count the individual characters of the string. For example, if the string was "abcabcabc" and the pattern to count was "abc" the method would return 3. This is so simple in perl with something like $num_count++ while $string =~/$pattern/g; But how to do it in ruby?!!?!? thanks
Advertisement
anyone at all know how to do this?
Take a quick look at this:

http://www.rubyist.net/~slagell/ruby/regexp.html

Should have something very similar and some better explanations than I could make myself.
James

This topic is closed to new replies.

Advertisement