gpt4 book ai didi

php - 检查 String 在 PHP 中是否只有用逗号分隔的整数

转载 作者:可可西里 更新时间:2023-11-01 13:40:03 25 4
gpt4 key购买 nike

我在 Regex 方面真的很空,这就是为什么无法在 PHP 中制作一个 Regex 来检查字符串是否具有这个特定的字符序列。

$str = '2323,321,329,34938,23123,54545,123123,312312';

表示检查字符串是否只包含以逗号 (,) 分隔的整数(不是小数,没有 alphabats 或其他任何东西)。

最佳答案

你可以使用这个正则表达式:

'/^\d+(?:,\d+)*$/'

代码:

$re = '/^\d+(?:,\d+)*$/';
$str = '2323,321,329,34938,23123,54545,123123,312312';

if ( preg_match($re, $str) )
echo "correct format";
else
echo "incorrect format";

关于php - 检查 String 在 PHP 中是否只有用逗号分隔的整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23206329/

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