From: Peter Szinek Date: 2008-11-13T07:46:45+09:00 Subject: Re: Matching > I am trying to parse out some characters from a string and I am having > some trouble because the string may have a space or it may not. > Basically I have a string that looks like this: > > Seattle, WA[SEA] or > Colorado Springs, CO[COS] or > Denver, CO[DEN] > > What I have so far to match the Seattle and Denver strings looks like > this: > > /[A-Z]{1,1}[a-z]+[,]\s[A-Z]+\[{1,1}/ > > This regular expression is trying to grab everything within the []; in > the cases above this would be SEA, COS, DEN. If you want to grab everything in brackets, why do you care about the text before them? You could do just: >> "Seattle, WA[SEA]"[/\[(.+)\]/,1] => "SEA" >> "Colorado Springs, CO[COS]"[/\[(.+)\]/,1] => "COS" etc. Cheers, Peter --- http://www.rubyrailways.com