如果我需要一个字符串来匹配这个模式:“word1,word2,word3”,在 PHP 中我如何检查字符串以确保它符合这个模式?
我想确保字符串符合以下任何一种模式:
word
word1,word2
word1,word2,word3,
word1,word2,word3,word4,etc.
最佳答案
preg_match("[^,]+(,[^,]+){2}", $input)
这匹配:
stack,over,flow
I'm,not,sure
但不是:
,
asdf
two,words
four,or,more,words
empty,word,
关于php - 检查字符串是否与模式匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1777101/