From: Eero Saynatkari Date: 2005-12-18T22:41:09+09:00 Subject: Re: How to grep the shortly matching in a string Arowana Lin wrote: > Robert Retzbach wrote: >> Arowana Lin schrieb: >> >>>I used regular expression to grep content from a web page,but it seems >>>ruby always match the longest string,but I need to fetch the shortly >>>matching. How can I do ? >>>Thanks for help! >>> >>> >>> >> Would be nice to see the regexp. Maybe using non-greedy multipliers will >> do. >> You could also use character classes like [^<>] to match chars between < >> and >. >> But I don't know what you want to match, so please show me :> > > Thanks Robert! > here is the example. > FormatFormat2Format3 > I use the code below to fetch "Format" and "Format2" in the table > feature=content.scan(/[([\w\s])*<\/td><\/tr>/) > I want to get each row into array feature,like > feature[0]=Format;feature[1]=Format2... > but it match all the row into > feature[0]=FormatFormat2Format3 Yes, you want the non-greedy version .*? instead of .* there. You can use ? with the *, + and {,} specifiers. E -- Posted via http://www.ruby-forum.com/.