Regex to check non-repetition of a set of characters

前端 未结 8 931
无人共我
无人共我 2020-12-19 12:47

Suppose I have the set of characters [ABC]. I\'m looking for a regex that would match any permutation of the superset except the empty set, i.e.



        
8条回答
  •  [愿得一人]
    2020-12-19 13:29

    This is not something that regular expressions are good at. You might just want to create a list of permutations instead, and then produce all unique substrings.

    something like:

    def matches(s, characters):
        if len(s) != len(set(s)):
            return False # not unique sequence of characters
        return set(s).issubsetof(set(characters))
    

提交回复
热议问题