From: William James Date: 2005-08-04T11:51:06+09:00 Subject: Re: regex question Joe Van Dyk wrote: > I have a file that contains the following contents: > > sw_corner = 1000,-1000 > ne_corner = -1000,1000 > > I want to read that file and figure out what the sw_corner and > ne_corner values are. Here's my following attempt, but it looks ugly. > How can I improve it? > > sw_corner = map_data.scan(/sw_corner = ([-\d]+),\s*([-\d]+)/)[0] > ne_corner = map_data.scan(/ne_corner = ([-\d]+),\s*([-\d]+)/)[0] map_data = DATA.read x = map_data.scan( /(sw|ne)_corner = (-?\d+),\s*(-?\d+)/ ) sw_corner = x.assoc("sw")[1,2] ne_corner = x.assoc("ne")[1,2] __END__ sw_corner = 1000,-1000 ne_corner = -1000,1000