求一段正则,该如何处理

WBOY
Release: 2016-06-13 13:07:27
Original
959 people have browsed it

求一段正则
需求:写模版引擎
原来的字符串:sfsdafsadfsadfsdfsdfsdfs{任意字符}gdfgdsfgdfgdf
其中任意字符里必须是a到z和-开头
如 {time()}替换成 ,,,,, {file_get_contents}替换成
注意:{}里面的()可有可无,最多一次


我是这样写的,一直错误
$new_str=preg_replace('/\{\s*([a-z|A-Z]*)\s*\}/is','',$new_str);
输出:


请按照我这样写 必须有\\1这样的

------解决方案--------------------
$new_str = 'dsafs{aaa}fff{time()}xxx';
echo $new_str=preg_replace('/\{\s*([a-z]+)(?:(\(\)))?\s*\}/isU','',$new_str);

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template