gpt4 book ai didi

php - preg_match : nothing to repeat/no match

转载 作者:可可西里 更新时间:2023-10-31 23:03:15 26 4
gpt4 key购买 nike

我正在使用这个:if(!preg_match('/^+[0-9]$/', '+1234567'))

并且得到:

Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1

有什么想法吗?


更新:现在使用这个:if(!preg_match('/^\+[0-9]$/', '+1234567'))

我找不到匹配项。

有什么想法吗?

最佳答案

+ 是一个特殊字符,表示前一个字符的 1 个或多个,不转义它就是将它应用于插入符号。用 \ 转义它,它将匹配文字加号。

if(!preg_match('/^\+[0-9]$/', '+1234567'))

编辑:

不匹配的原因是因为你指定了 0-9 中的 1 个数字和字符串的末尾 $。您需要使它的位数可变。

if(!preg_match('/^\+[0-9]+$/', '+1234567')) {

较短的版本:

if(!preg_match('/^\+\d+$/', '+1234567')) {

关于php - preg_match : nothing to repeat/no match,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3223059/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com