From: Robert Dober Date: 2007-06-11T02:31:13+09:00 Subject: Re: regex: get the first match On 6/10/07, Trochalakis Christos wrote: > 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! > You are welcome ;) Robert -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw