(From a previous question I asked) a way to find if a poker hand that has 2-, 3-, or 4-of-a-kind would be with a regex like the following:
REGEX = (.)(.*?\1){1,3}
re.search(REGEX, 'JAJ24').group(1)
'J'
For example, it works at the following regex101 link here: https://regex101.com/r/MAugJC/3.
How could I also assert that the length of the string itself is exactly 5 chars? Without doing another regex, the only thing that I could think of was in doing a lookaround that totals 5 chars, for example, lookahead 5 or lookahead 4 + lookbehind 1, etc. Would it be possible to do this in a regex with another (simpler) method?
Here are some examples of what it should and should not match:
2Q33K # yes, 3's
KK238 # yes, K's
JAJ29 # yes, J's
K246K # yes, K's
KJKKK # yes, K's
3JKA9 # no pair
94822 # yes, 2's
94228 # yes, 2's
22849 # yes, 2's
3JKA9K8 # no, length != 5