Home  >  Article  >  Backend Development  >  求教一个正则问题

求教一个正则问题

WBOY
WBOYOriginal
2016-06-23 13:23:01813browse

preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", “ext/plain; charset=utf-8”)
错误
preg_match(): Compilation failed: invalid range in character class at offset 7
正则不熟 求救


回复讨论(解决方案)

echo preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", "ext/plain; charset=utf-8"); //1

没有问题!估计是其他地方的问题

为什么你的php会报错?我用你的正则显示的是匹配成功啊。。。

<?phpheader('content-type:text/html;charset=utf-8');//$res = preg_match("/^([\.-\w]+)\/([\.-\w]+);\s(\S)*$/i", 'ext/plain; charset=utf-8');$res = preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", "ext/plain; charset=utf-8");if($res){	echo "匹配!";}else{	echo "匹配失败!";}?>

估计是服务器问题。debian线上正常。本地MAC和windows都有问题。无奈只能换个方法写

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn