Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 字符和数字至少出现一次_Regex - Fatal编程技术网

Regex 字符和数字至少出现一次

Regex 字符和数字至少出现一次,regex,Regex,我希望下面的正则表达式可以匹配字符串“A34CVDREREEVBF98F04389” 但是,我发现正则表达式也可以匹配以下字符串 000001111122222333334 #The string doesn't include a character. AbstractAlgebraTheory #The string doesn't include a digit. 它是否有办法确保字符和数字在字符串中至少出现一次?使用前瞻 \b(?=.*\d)(?=.*[a-zA-

我希望下面的正则表达式可以匹配字符串“A34CVDREREEVBF98F04389”

但是,我发现正则表达式也可以匹配以下字符串

  000001111122222333334 
  #The string doesn't include a character.

  AbstractAlgebraTheory 
  #The string doesn't include a digit.
它是否有办法确保字符和数字在字符串中至少出现一次?

使用前瞻

\b(?=.*\d)(?=.*[a-zA-Z])[0-9a-zA-Z]{21}\b
如有必要,添加锚固件

^(?=.*\d)(?=.*[a-zA-Z])[0-9a-zA-Z]{21}$
^(?=.*\d)(?=.*[a-zA-Z])[0-9a-zA-Z]{21}$