From: "Wolfgang Nádasi-Donner" Date: 2005-08-01T01:31:05+09:00 Subject: Re: [Brainstorming Input] Ruby-Oniguruma interoperability on Named Groups >>>>> snip >>>>> "Dominik Bathon" schrieb im Newsbeitrag news:op.sur8hdg2d62ajc@localhost... On Sat, 30 Jul 2005 20:31:03 +0200, Wolfgang N�dasi-Donner .. .. .. ... 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? >>>>> snap >>>>> First of all - I made a mistake. Please forget all '\k...'-stuff. This is the same as '\1', '\2', ..., which means, it is a reference to a match result of applying this group in the actual matching process. We are talking here about the '\g...' reference only, which is a call to the group during match time. For simply prematch time replacement the '#{...}' Ruby construct is still usable. It is clear for my understanding that in the Ruby environment the class 'Regexp' must be changed, as well as 'Oniguruma' itself, because it must be able to find the predefined patterns during a match process. My suggestion based this on the prerequisite to have minimal changes in Oniguruma and Ruby's Regexp class - making such changes acceptable and possible ;-) This implies not to change existing things in Ruby and Oniguruma. Insofar I prefer the usage of '\g' instead of some other notation, but that are only my thoughts for it. The idea of using hashes in Ruby and an extension of class Regexp having a 'with' method sounds very good. This method is a candidate for building the connection to Oniguruma, which then knows where to search for a '(?...)' expression, if it isn't defined in the actual regular expression, but referenced via '\g' there. The 'with' method may be able to have a list of hashes as parameter (or even multiple hashes as parameters), because one may use more than one predefined pattern groups (may happen if one uses a general pattern library and a special one for the application). -- Wolfgang N�dasi-Donner wonado@donnerweb.de