[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Ruby version of preg_match_all?

Nathaniel Talbott

9/19/2003 1:37:00 PM

David Heinemeier Hansson [mailto:david@loudthinking.com] wrote:
> I'm having a hard time finding a way of archiving the functionality
> of PHP's preg_match_all[1] in Ruby. Am I just not looking in the
> right places? I have a string like "SomethingCool SomethingWild
> Something AnotherCool" and want to use a regular expression, like
> /(\w+Cool)/, to get all the *Cool words back in an array
> (["SomethingCool", "AnotherCool"]).

Try String#scan:

"SomethingCool SomethingWild Something AnotherCool".scan(/\b(\S+Cool)\b/)

HTH,


Nathaniel

<:((><