nonopolarity
nonopolarity

Reputation: 151126

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.

Upvotes: 2

Views: 333

Answers (2)

steenslag
steenslag

Reputation: 80075

split( regex ) returns an array, leaving out all matches. Sometimes it's easier to specify what you don't want to see.

Upvotes: 1

sepp2k
sepp2k

Reputation: 370357

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.

Upvotes: 0

Related Questions