From: Peter Szinek Date: 2008-11-13T07:56:19+09:00 Subject: Re: Matching --Apple-Mail-3--884557490 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On 2008.11.12., at 23:46, Peter Szinek wrote: >> 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. Here is a 'full' solution that should cover these cases: >> "Colorado Springs, CO[COS]"[/(\w|\s)+, [A-Z]{2}\[(.+?)\]/,2] => "COS" >> "Denver, CO[DEN]"[/(\w|\s)+, [A-Z]{2}\[(.+?)\]/,2] => "DEN" Cheers, Peter --- http://www.rubyrailways.com --Apple-Mail-3--884557490--