Sorry about the title, I couldn’t come up with a clean way to ask my question.
In Python I would like to match an expression ‘c[some stuff]t’, where [some stuff] could be any number of consecutive a’s, b’s, or c’s and in any order.
For example, these work:
‘ct’, ‘cat’, ‘cbbt’, ‘caaabbct’, ‘cbbccaat’
but these don’t:
‘cbcbbaat’, ‘caaccbabbt’
Edit: a’s, b’s, and c’s are just an example but I would really like to be able to extend this to more letters. I’m interested in regex and non-regex solutions.
Not sure how attached you are to regex, but here is a solution using a different method:
The string matches if a set of the middle characters is a subset of
set('abc')and the number of groups returned bygroupby()is the same as the number of elements in the set.