Jump to content
  • Advertisement
Sign in to follow this  
3fast3furious

ruby regular expressions

This topic is 4128 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!