[Solved] Regex to find if a string contains all numbers 0-9 be it in any order [duplicate]


This solution can handle all sorts of strings, not only numeric characters.

s1 = 'ABC0123091274723507156XYZ' # without 8
s2 = 'ABC0123091274723507156XYZ8'

len(set("".join(re.findall(r'([\d])', s1)))) == 10 # False
len(set("".join(re.findall(r'([\d])', s2)))) == 10 # True

How it works:

Find all digits in the string with regex findall. Join all matches to one string and get unique characters by putting it in a set. Then count the length of the set. If all digits are represented the length will be 10.

solved Regex to find if a string contains all numbers 0-9 be it in any order [duplicate]