Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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_Coldfusion - Fatal编程技术网

Regex 正则表达式来匹配字符串中的确切字符数

Regex 正则表达式来匹配字符串中的确切字符数,regex,coldfusion,Regex,Coldfusion,我想得到一个9位整数的匹配。我正在扫描的文本长度可以是1-200个字符 我遇到的问题是,如果输入有一系列大于9的数字,我不想匹配。我还需要匹配整个输入字符串是否为9位。或以9位数字开始或结束 我试过: d{9} > This matches sub-strings longer than 9 digits d{9}(\D) > This works unless the sub-string is at the end since this expects some

我想得到一个9位整数的匹配。我正在扫描的文本长度可以是1-200个字符

我遇到的问题是,如果输入有一系列大于9的数字,我不想匹配。我还需要匹配整个输入字符串是否为9位。或以9位数字开始或结束

我试过:

d{9}      >  This matches sub-strings longer than 9 digits
d{9}(\D)  >  This works unless the sub-string is at the end since this expects some character after the 9 digits.
我已经搜索了很多,但我没有找到这个确切的问题。有什么想法吗


注意:我碰巧正在与ColdFusion合作处理这个特殊问题,但我希望通用正则表达式能够做到这一点。如有必要,我可以用CFML对其进行编码。

使用替代项匹配非数字或字符串的开头/结尾:

(^|\D)\d{9}($|\D)

数字本身应该是一个单词,还是可以是字母?如果它是一个单词,请使用
\b
单词边界模式。它周围可以有任何东西,除了其他数字(或周围没有任何东西)。如果输入为abd123456789xyz,则为匹配。但是abd1234567890xyz不匹配,因为它有额外的数字。Abd sdf 123456789[行尾/文件]将匹配。谢谢