You can generally use a capture group and back reference to detect consecutive characters. For example, in grep
:
$ echo abc | grep '\([a-z]\)\1'
$ echo abbc | grep '\([a-z]\)\1'
abbc
The parentheses around the thing you're looking for capture the resultant matching portion and this portion is then substituted for \1
in the remainder of the regex.
In terms of your specific test cases, see below:
$ echo 12345 | grep '\([a-zA-Z0-9]\)\1' >/dev/null; echo $?
1
$ echo 11145 | grep '\([a-zA-Z0-9]\)\1' >/dev/null; echo $?
0
$ echo aaa664 | grep '\([a-zA-Z0-9]\)\1' >/dev/null; echo $?
0
You can see you get 1
for a successful string, 0
for a bad one (that matches the regex).
Depending on what language you're using, the methods to detect a match or not may change slightly but the overall concept of capture group and back reference should be the same.