nature_true 2013-06-28 02:59 采纳率: 0%
浏览 2140

简单正则表达式解析问题

以下为对方给的解析模板的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;
}

  • 写回答

1条回答

  • q107770540 2014-12-06 12:16
    关注
     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; ?>");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 matlab解优化问题代码
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?