Let me first explain the reason for and the kind of this message.
I have an vague idea on coming to more readable Regular Expression, and the possibility to build Libraries of
Regular Expressions. The hook are the named groups ('(?<name>...)') which are part of Oniguruma. The idea was
influenced by the ancient Snobol4-Language and its '*'-operator for unevaluated expressions.
This input is brainstorming material and not a change proposal, because it is not mature enough. I hope that
something like this will appear sometimes in the future in Ruby.
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.
In detail a regular expression that consists only of a named group definition (starts with '(?<name>') kann be
registered by something like 'Regex.register(/(?<example>a|b|c|d)/)', and be deleted by
Regex.remove('<example>'). 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 '/(?<example>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.
These Object can later on be referenced in regular expressions by '\k<name>' or '\g<name>' as if they were
defined there.
This could made regular expressions be much more readable, because one can build them based on smaller parts,
one can build special Libraries of regular expression parts that are usable in the applications, and one can
use regular expression parts that were build by others without complete understanding of their details.
I think that this is worth to think about.
Best regards, Wolfgang
···
--
Wolfgang Nádasi-Donner
wonado@donnerweb.de