<?php
//false
echo preg_match('/[^(test)]/','test');//true
echo preg_match('/[^(test)]/','this is a test');//true
echo preg_match('/test/','this is a test');
?>结果输出为:011,0代表false,1代表true
//false
echo preg_match('/[^(test)]/','test');//true
echo preg_match('/[^(test)]/','this is a test');//true
echo preg_match('/test/','this is a test');
?>结果输出为:011,0代表false,1代表true
可是第二、三项中确实包含了 'test'字符串呀
[^t]不匹配包含t的字符串
[^e]不匹配包含e的字符串.....
但要匹配不包含test(不是单一的字母,而是这个单词),该怎么写?
{
return preg_match('/test/',$str) ? "false": "true";}
echo tf('test').'<br>';echo tf('this is a test').'<br>';echo tf('this is');
?>输出false
false
true
print_r($regs);
print_r($regs);?>说实在的,这个例子很差,这和在'abcd'中取出某个字母一样说这个例子不好,是因为它没有规律性,失去了正则表达式的意义不知道你想要什么样的效果