← Back to challenges

RegEx Exercise #7: Distinct Digits

PythonHardregexstringsvalidation

Instructions

Write a regular expression that matches numbers whose digits are not repeated (i.e. digits are distinct).

Examples

pattern = "yourregularexpressionhere"

bool(re.match(pattern, "123")) ➞ True

bool(re.match(pattern, "112233")) ➞ False

bool(re.match(pattern, "1025")) ➞ True

Notes

  • You don't need to write a function, just the pattern.

  • Input is a number as a string.

  • You can find all the challenges of this series here.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.