^([a-zA-Z0-9](?(?!__|--)[a-zA-Z0-9_\-])+[a-zA-Z0-9])$
or
^([a-zA-Z0-9](?(?!__|--)[a-zA-Z0-9_\-]){0,4}[a-zA-Z0-9])$
to limit to 6 characters like your example.
The magic sauce is the
negative lookaround assertion.
Please mark
answered if I helped you.
—Yvan