From: James Edward Gray II Date: 2007-07-15T02:51:43+09:00 Subject: Re: [QUIZ] Maximum Sub-Array (#131) On Jul 14, 2007, at 12:21 PM, Anton wrote: > Hello, everybody! I am new here. I am also relatively new to ruby. > > I don't know if it's OK to ask questions here before the 48 hours > period ends. So I am going to shoot straight and ask. > > I am trying to create a perfect regexp match string to match an array > string like [1, -1, 4, 5] > So far the best I've came up with is /^\[-*\d+,*.*\]$/ > > If I add \s+ the string doesn't match. /^\[-*\d+,*\s+.*\]$/ And I have > no idea why... Well, if I understand right, you want a regex to match an array of one or more integers? I would probably use: /\A\s*\[\s*-?\d+(?:\s*,\s*-?\d+)*\s*\]\s*\Z/ Is that what you are after? James Edward Gray II