May-11-2020, 02:58 PM
Is there really something separating each character, or are you just looking for any repeated character? (You use the term "delimiter", but I don't see any).
If you really just want repeated characters, you could do the following. The grouping is a bit odd, but you can pull the repeated strings out of the first part of each tuple.
If you really just want repeated characters, you could do the following. The grouping is a bit odd, but you can pull the repeated strings out of the first part of each tuple.
>>> s = ".nnddd9999999999ddnn." >>> re.findall(r"((.)\2+)", s) [('nn', 'n'), ('ddd', 'd'), ('9999999999', '9'), ('dd', 'd'), ('nn', 'n')]Or if you really just have a few characters and you want all the strings of them, you could do what you did earlier, but add the repetition (+) operator to them:
>>> re.findall(r"(\.+|n+|d+|9+)",s) ['.', 'nn', 'ddd', '9999999999', 'dd', 'nn', '.']