Jim Marshall
8/6/2007 4:31:00 AM
On 8/5/07, Spike Grobstein <spike666@mac.com> 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