From: Daniel N Date: 2007-07-13T17:33:17+09:00 Subject: Re: Regexp Question - Merb::Router ------=_Part_25032_3629372.1184315598695 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/13/07, Robert Klemme wrote: > > 2007/7/13, Daniel N : > > On 7/13/07, Robert Klemme wrote: > > > > > > 2007/7/13, Daniel N : > > > > Hi, > > > > > > > > I'm looking through the Merb::Routing code and I've found a regexp > that > > > I > > > > can't figure out how it works. > > > > > > > > Merb::Router::SECTION_REGEXP #=> /(?::([a-z*_]+))/ > > > > > > > > It takes a route definition string, like "/products/:model/:id" and > > > > extracts the "model" string on the first pass, and later the "id" > > > string. > > > > > > > > Can anyone shed some light on what the > > > > ?:: > > > > part does? I haven't found it in any of the documentation for Ruby > > > Regexps > > > > that I've found. > > > > > > It's actually *two* parts: (?:) is a non capturing regexp group. The > > > second ":" literally matches a single colon. > > > > > > Kind regards > > > > > > robert > > > > > > Thanx Robert, > > > > I've not heard of that before. Makes searching on google much easier :) > > > > /(?::([a-z*_]+))/ > > > > I guess this means that a nested group within this non capturing group > (this > > case) is captured though since the $1 variable is refered to later. > > Exactly. Btw, in your case I'd probably use another regexp. Some samples: > > irb(main):001:0> "/products/:model/:id".scan %r{/:([^/]+)} > => [["model"], ["id"]] > irb(main):002:0> "/products/:model/:id".scan %r{:([^/]+)} > => [["model"], ["id"]] > irb(main):004:0> "/products/:model/:id".scan %r{:[^/:]+} > => [":model", ":id"] > > But of course I do not know the full spec of your input data. > > Kind regards > > robert > I'm just trying to understand that regexp's place in the Merb routing code at the moment. You've cleared it up nicely for me. Thankyou Daniel ------=_Part_25032_3629372.1184315598695--