好的,假设我想在一个句子中匹配3个单词...但我需要以任意顺序匹配它们,例如:
$sentences = Array(
"one two three four five six seven eight nine ten",
"ten nine eight seven six five four three two one",
"one three five seven nine ten",
"two four six eight ten",
"two ten four six one",
);
我需要匹配单词 "two"、"four" 和 "ten",但它们可以以任何顺序出现,并且它们之间可以有其他单词也可以没有。我试过了。
foreach($sentences AS $sentence) {
$n++;
if(preg_match("/(two)(.*)(four)(.*)(ten)/",$sentence)) {
echo $n." matched\n";
}
}
但是这只匹配句子1,而我需要在句子1、2、4和5中匹配。
希望你能帮助... 谢谢! (对我的英语很抱歉)