Iterate over the input string, finding a match of this expression each iteration, chopping off up to and including the first character of the previous match, until there is no match:
((\d)((?!\2)\d)((?!\2)(?!\3)\d))
You could do a findAll, but then you won't detect overlapping matches, such as "12321" would have. You'd only find the first: "123"
Of course, this only works for digits. If you want to match word characters also, you could do:
((\w)((?!\2)\w)((?!\2)(?!\3)\w))
If you want a longer length, just follow the pattern when building a regex:
((\w)((?!\2)\w)((?!\2)(?!\3)\w)((?!\2)(?!\3)(?!\4)\w))
So, I'll just hopefully Python-correct code... :
max=<your arbitrary length>
regex = "((\\w)"
for i in range(1, max-1):
regex += "("
for j in range(2, i+1):
regex +="(?!\\"+j+")"
regex += "\\w)"
regex = ")"
Phew
123121
, do you want to get123
or123, 231, 312
? – Fulfillment