Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在“php”中创建一个正则表达式,它检查一个字符串是否由数字“:”““”,“\回车”组成。我知道这很简单,但我在这个领域有点绿。提前致谢 。
不能只用PHP的is_numeric()方法吗?
is_numeric()
在 PHP 文档中查看 is_numeric
您可以使用
/^(?=.*\d)(?=.* )(?=.*:)(?=.*,)(?=.*\r)[: \d,\r]+$/
^是字符串的开头
^
.匹配任何单个字符
.
.*匹配 0 到多个字符 ( .)
.*
(?=.*\d)是一个前瞻,只有当它有一个数字时才会进一步匹配..
(?=.*\d)
[abcd]是一个匹配 a OR b OR c OR d 的字符类
[abcd]
$是字符串的结尾
$