in reply to Why would one want in a regex a class with only a single entry?
One might not hand-craft a regexp with single-entry character classes, but how about code-built regexps? When a regexp is built programatically, and there's a situation where one time a character class may contain one entry, and another times "n" entries, the fact that one-entry character classes are legal is simply one less thing to worry about. In that regard, I can see why it may be useful for such a construct to exist and to be legal.
And actually, there may be some single-entry character classes that are helpful, particularly among negated classes:
/[^T]ap/ # Match anything that's not 'T', followed by 'ap'
This is one time where a single-entry character class is actually probably the best way to do it.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why would one want in a regex a class with only a single entry?
by parv (Parson) on Mar 25, 2008 at 06:31 UTC | |
by davido (Cardinal) on Mar 25, 2008 at 06:39 UTC | |
by parv (Parson) on Mar 25, 2008 at 08:59 UTC | |
by ack (Deacon) on Mar 26, 2008 at 03:54 UTC | |
|
Re^2: Why would one want in a regex a class with only a single entry?
by ack (Deacon) on Mar 26, 2008 at 03:49 UTC |