From: Josh Cheek Date: 2011-08-11T10:15:57+09:00 Subject: Re: Reg Ex Help Required --bcaec51a8f6aa351a904aa308934 Content-Type: text/plain; charset=ISO-8859-1 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. --bcaec51a8f6aa351a904aa308934--