From: Rob Biedenharn Date: 2008-11-14T09:16:15+09:00 Subject: Re: Matching On Nov 13, 2008, at 5:49 PM, Shandy Nantz wrote: > As you can imagine the regex wouldn't ketch this expression. So I > tried > this: > > params[:airport][:city].gsub(/$\s/, "") > [/(\w|\s)+, [A-Z]{2}|[A-Z][a-z]{1,}\[(.+?)\]/,2] > > And al' bee it caught the Torono, Canada[YYZ]. Now, however, it > fails to > get the Denver, CO[DEN]. I must have a complete lack of understanding > when it comes to regex because I always thought that the "|" in the > above statement meant "or", as in, try and match TWO A-Z OR one A-Z > FOLLOWED BY one or more a-z. I guess I am drawing a total blank > because > I look at the revised code above and I think it should match all the > above cases and I cannot figure out for the life of me where it is > failing. Can someon ehelp, thanks > > -S Oh, I see part of your problem: You need to group the alternation to see what you want. => An UPPER with one or more lowers, followed by some characters within square brackets v---------------------v /(\w|\s)+, [A-Z]{2}|[A-Z][a-z]{1,}\[(.+?)\]/ ^----------------^ => Some word or space characters, a comma, and 2 letters I think you intended to have: v------v /(\w|\s)+, (?:[A-Z]{2}|[A-Z][a-z]{1,})\[(.+?)\]/ ^------------^ Grouped with (?: ) which is a non-capturing group. (But my earlier message still holds.) -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com