In Ruby, is scan() the only function that can return multiple results of regular expression matching?
Just to know more methods that can accomplish the 开发者_如何转开发same thing.
split( regex )
returns an array, leaving out all matches. Sometimes it's easier to specify what you don't want to see.
There are only two methods in the standard library which match a regular expression multiple times: gsub
(and gsub!
, of course) and scan
. gsub
returns a single string, so, yes, scan
is the only one the returns multiple results.
精彩评论