From: Trochalakis Christos Date: 2007-06-11T02:20:13+09:00 Subject: Re: regex: get the first match On Jun 10, 3:22 pm, GrzechG wrote: > > I want to parse a tagged string like this: "this ismy > > string" > > > i am doing: > > >>> "this ismy string".scan(/(.*)<\/i>/) > > => [["this ismy string"]] > > > What i want is a regex that will return the *first* segment that > > matches. > > in the above case -> [["this is", "my string"]] > > The solution is : > > "this ismy string".scan(/(.*?)<\/i>/) > => [["this is"], ["my string"]] > > The regexp scope is default maximum as is possible to find. > If you use '?' character you minimze the scope. > (.*?) instead of (.*) and the part of string don't be include > into one result. > > Regards, > Grzegorz Golebiowski Thanks Grzegorz, nice trick!