From: Mark Thomas Date: 2008-11-19T12:16:31+09:00 Subject: Re: ruby global regex question. On Nov 18, 7:08 pm, knohr wrote: > For the life of me, i can't figure out a ruby equivalent to perl's /g > > basically, i want to do the following > > while htmlSource=~m/(.*?)<\table>/g do >    tableSource=$1 >    tableSource=~m/Index (\d+)/ >    indexNumber=$1 > >    while tableSource=~m/(.*?)<\/tr>/g do >       tableRowSource=$1 >       doSomethingWith(tableRowSource, indexNumber) >    end#while tableSource > > end#while htmlSource > > I will actually need to pull multiple vars, not just a single one, > from the regex > I will need to do the outer loop an unknown amount of times per > document (0-20) and i will need to loop the inner an unknown amount of > times (0-29) > > Thread safe would be a plus. Would fast be a plus? No nested loop? require 'nokogiri' doc = Nokogiri::HTML(htmlSource) doc.search('//tr').each do |row| index = row.xpath('ancestor::table/*[contains("Index",.)]') doSomethingWith(row.text,index[/(\d)/]) end The location of the element containing the index may have to be modified. -- Mark.