From: Dominik Bathon Date: 2005-07-31T23:40:38+09:00 Subject: Re: [Brainstorming Input] Ruby-Oniguruma interoperability on Named Groups On Sat, 30 Jul 2005 20:31:03 +0200, Wolfgang N�dasi-Donner wrote: > Now the idea. > > Ruby and Onigurama should be extended somehow to allow Ruby-objects > (usually regular expressions) to be > registered somehow to the class Regexp, so that they can be referenced > later in regular expressions. I think I generally like the idea to compose regular expressions that way ... > In detail a regular expression that consists only of a named group > definition (starts with '(?') kann be > registered by something like 'Regex.register(/(?a|b|c|d)/)', > and be deleted by > Regex.remove(''). If the regular expression is assigned to a > variable this can be used, how to manage > this in the 'remove' case has to be clearified. I used class methods for > this example, but it may be better to > introduce a named Regexp objects which will be created by something like > '/(?a|b|c|d)/.create. Some > possibility for explicit deletion should be there, because the regex > engine Oniguruma must know about the > object to take care about. ... but I think registering all named groups in one global place is not a good idea (even if you can unregister): what if two libraries use the same group names? I think there would be many name clashes. So here is another idea: Let the caller manage the named groups himself. Maybe in arrays or hashes. Something like: groups = [/(?a|b|c|d)/, /(?e|f|g)/] or with hashes: groups = { "example" => /a|b|c|d/, "example2" => /e|f|g/ } or maybe in some specialized named groups library class. > These Object can later on be referenced in regular expressions by > '\k' or '\g' as if they were > defined there. To use those groups I would suggest something like: /\k/.with(groups) RegExp#with would return the "composed" RegExp that can be used like any other RegExp. What do you think? Dominik Disclaimer: I do not really know how named groups work in Oniguruma, just wanted to point out that one global registry might be a bad idea.