From: Josh Cheek Date: 2011-08-11T10:17:46+09:00 Subject: Re: Reg Ex Help Required --20cf307ca1e86f81f304aa308d8e Content-Type: text/plain; charset=ISO-8859-1 On Wed, Aug 10, 2011 at 8:15 PM, Josh Cheek wrote: > On Wed, Aug 10, 2011 at 7:44 PM, Chad Perrin wrote: > >> On Thu, Aug 11, 2011 at 07:34:54AM +0900, Josh Cheek wrote: >> > >> > I'd use split as well, but I'd probably do it like this: >> > >> > str = "abc = 100.300" >> > variable, value = str.split('=', 2).map(&:strip) >> > variable # => "abc" >> > value # => "100.300" >> >> I'd probably use a regex for the split sequence rather than a literal to >> account for variations in whitespace, rather than a map: >> >> variable, value = str.split(/\s*=\s*/, 2) >> >> . . . but either way works. >> >> -- >> Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] >> > > It seems to me that there could be whitespace on either end, ie > > " > def whatever > var = 123 > end > " > > This shows a very common example of leading whitespace, so I thought using > strip would be better. > Although, I suppose you could make the argument that an actual parser would be best. --20cf307ca1e86f81f304aa308d8e--