【www.gdgbn.com--php函数】

php教程正则指定字符串内容preg_match函数之说明
虽然代码不多,但简单明了
复制代码 代码如下:

preg_match("/^(?!string)/", "aa") === true

这个用来验证一个字符串是否是非"string"开头的,
在perl或支持perl的正则表达式的语言(如php)中,可以用前看声明来做到这一点,正则表达式是:
复制代码 代码如下:

preg_match("/.*(?!.txt)$/", "aa")

意思是匹配所有不以.txt结尾的名字


preg_match -- 进行正则表达式匹配
说明
int preg_match ( string pattern, string subject [, array matches [, int flags]])


在 subject 字符串中搜索与 pattern 给出的正则表达式相匹配的内容。

如果提供了 matches,则其会被搜索的结果所填充。$matches[0] 将包含与整个模式匹配的文本,$matches[1] 将包含与第一个捕获的括号中的子模式所匹配的文本,以此类推

本文来源:http://www.gdgbn.com/jiaocheng/28658/