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
In reply to Re: Why would one want in a regex a class with only a single entry?
by davido
in thread Why would one want in a regex a class with only a single entry?
by ack
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |