AndrewShmig
AndrewShmig

Reputation: 4923

How to iterate through string for all regexp matches in Ruby?

We have a string: "<b><c><d><e>"

And this Regexp: /<(\w+)>/i

How can I get ALL of the matches from current string?

Upvotes: 5

Views: 2197

Answers (1)

Paweł Obrok
Paweł Obrok

Reputation: 23194

"<b><c><d><e>".scan(/<(\w+)>/)

See scan on ruby-docs

Upvotes: 10

Related Questions