function rall(r, s) { var a=[],t,g=r.global; do {t=r.exec(s);if (!t) break; a.push(t);} while (g); return a; } var r=/.*?(.)(?=(.*?\1.*))/g; var res=rall(r,password);
res will be an array of arrays containing all matches of repeated characters.
RegExp uses appearance to find out if the found character (recorded in the first group) will appear again later in the line.
A password of type secret elements will appear as:
"[["s","s","ecret elements"], ["e","e","cret elements"], ["cre","e","t elements"], ["t","t"," elements"], [" e","e","lements"], ["le","e","ments"]]"
The second element in each sub-array is a multiple-match character.
If there are no repetitions, the array will have a length = 0, which is easy to check, for example:
if (rall(r,password).length==0) console.log('password is OK!');