I need a regex that will match DK | EK | KD | KE. Seems simple enough with K[D|E]|[D|E]K
but this does not work (at least not at regx101) for a sequence with KDK or KEK. This regex will match the first 2 characters, but will not match the final 2 characters. It will match a string of 4 characters, such as KDKD or KDKE or KEKE, but adding a K to any of these also fails to match the final 2 DK or EK characters.
What regex will allow these types of sequences (some of which are palindromes) to match?
EDIT To clarify a bit, KDK would match the first option (KD) but not the second option (DK) in my simple regex. Clearly these two matches overlap and I'm looking for a regex that will allow the match when there is an overlap.
EDIT2 And, I've realized this isn't necessarily limited to palindromes - original post corrected, above.
EDIT3 All of the following should match. I don't claim this is an exhaustive list. For non-matches, any character that does not consist of part of the list pairs (KD, KE, EK, DK) should not match. For example KDDDK would match the first 2 characters (KD) and the last 2 characters (DK) but not the central D as it is never preceded nor followed by a K.
KD
KE
EK
DK
KDK
KEK
EKE
DKD
EKD
DKE
KDKD
KDKE
KEKD
KEKE
KDDK
KEEK
DKDK
EKDK
KDEK
DKKD
DKKE
EKKE
EKKD
KEEKE