以下为对方给的解析模板的php正则,想在java里使用,因为是正则小白,希望得到大家的帮助,感激,谢谢!!
我的疑问:我对preg_replace()理解;此方法需要三个参数,第一个为正则表达式,第二个为替换成的字符串,第三个为模板代码,最终返回替换后的模板代码。在java中第一个参数报错,不知道是不是语法不对,如果在java中又该如何使用,希望大侠们指点!!
/**
* 解析模板
*
* @param $str 模板内容
* @return ture
*/
public function template_parse($str) {
$str = preg_replace ( "/{view\s+(.+)}/", "<?php include view(\1); ?>", $str );
$str = preg_replace ( "/{template\s+(.+)}/", "<?php include template(\1); ?>", $str );
$str = preg_replace ( "/{include\s+(.+)}/", "<?php include \1; ?>", $str );
return $str;
}
表法式
str=Regex.Replace(str,"{view\\s+(.+)}","<?php include view($1); ?>");
str=Regex.Replace(str,"{template\\s+(.+)}","<?php include template($1); ?>");
str=Regex.Replace(str,"{include\\s+(.+)}","<?php include $1; ?>");
str=Regex.Replace(str,"{view\\s+(.+)}","<?php include view($1); ?>");
str=Regex.Replace(str,"{template\\s+(.+)}","<?php include template($1); ?>");
str=Regex.Replace(str,"{include\\s+(.+)}","<?php include $1; ?>");
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。