From: Jim Marshall Date: 2007-08-06T13:31:07+09:00 Subject: Re: accessing all matches using regex On 8/5/07, Spike Grobstein wrote: > while (/href=\"([^\"]+)\"/) { > ## do stuff... > } > ... > I can't figure out how to that in ruby. how can I iterate over all > matches in a string? I could split the lines, but sometimes there may be > two or more matches on a single line. > > is there a nice, clean, ruby way to do this? > Have a look at String#scan ("ri String#scan" might do it, depending upon your installation). For example, >some_string_with_html.scan(/href=\"([^\"]+)\"/) do |match| > do_stuff_with match >end