If I have a set of characters like \"abcdefghij\" and using this characters, I generate random a password using this characters. A generated password can have, for example,
You could use something like:
/^ (?:(.) (?!\1) # neighbor characters are not identical (?!(?>.*?\1){2}) # character does not occur more than twice )* \z/x
Perl quoting, the atomic group can be removed if not supported.
In Java regex it could be written like:
^(?:(.)(?!\1|(?:.*?\1){2}))*\z