regex - Finding all the ten different digits in a random string -


sorry if answered somewhere, couldn't find it.

i need write regexp matches on strings contain digits 0 9 once. example:

e8v5i0l9ny3hw1f24z7q6 

you can see numbers [0-9] present once , in random order. (letters present once, advanced quest...) must not match if digit missing or if digit present more 1 time.

so best regexp match on strings these? still learning regex , couldn't find solution. pcre, running in perl environment, cannot use perl, regex part of it. sorry english , thank in advance.

what pattern verify string:

^\d*(?>(\d)(?!.*\1)\d*){10}$ 
  • ^\d* starts amount of characters, no digit
  • (?>(\d)(?!.*\1)\d*){10} followed 10x: digit (captured in first capturing group), if captured digit not ahead, followed amount of \d non-digits, using negative lookahead. 10x digit, not ahead consecutive should result in 10 different [0-9].

\d shorthand [0-9], \d negation [^0-9]

test @ regex101, regex faq


if need digit-string then, extract digits, e.g. php (test eval.in)

$str = "e8v5i0l9ny3hw1f24z7q6";  $pattern = '/^\d*(?>(\d)(?!.*\1)\d*){10}$/';  if(preg_match($pattern, $str)) {   echo preg_replace('/\d+/', "", $str); } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -