From: Ross Bamford Date: 2006-03-28T02:17:03+09:00 Subject: Re: Simple pattern matching On Tue, 2006-03-28 at 01:58 +0900, Minkoo Seo wrote: > Hi group. > > Sorry for newbie question. Given the line like > > node: { title: "15597629" label: "up[0,18 p:-2270.125]" } > > How can I parse the above string into "15597629" and "up[0,18 > p:-2270.125]"? There are numbers in the first "..." and a-z, :, [, and > ] in the second "..." part. Here are a couple of ways: s = 'node: { title: "15597629" label: "up[0,18 p:-2270.125]" }' # => "node: { title: \"15597629\" label: \"up[0,18 p:-2270.125]\" }" s =~ /title:\s("[^"]*")\slabel:\s("[^"]*")/ # => 8 $1 # => "\"15597629\"" $2 # => "\"up[0,18 p:-2270.125]\"" s.scan(/"[^"]*"/) # => ["\"15597629\"", "\"up[0,18 p:-2270.125]\""] -- Ross Bamford - rosco@roscopeco.REMOVE.co.uk