Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

string

regex

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?

like image 974
AndrewShmig Avatar asked Jul 28 '11 10:07

AndrewShmig


1 Answers

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

See scan on ruby-docs

like image 58
Paweł Obrok Avatar answered Nov 14 '22 22:11

Paweł Obrok