CSDNRGY
2017-03-01 02:35
采纳率: 99.3%
浏览 827

为什么这个正则表达式一执行,就会非常的卡?

目标

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/base/include.jsp"%>
<%@ page import="net.bjqfy.civairdef.web.common.constant.CommonConstant" %>
<%String path = request.getContextPath(); %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=8" />
        <title><%=CommonConstant.TEST_TITLE_CN%></title>
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
        <link rel="stylesheet" type="text/css" href="../public/css/style.css">
        <link rel="stylesheet" type="text/css" href="../public/jquery-easyui-1.4/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="../public/jquery-easyui-1.4/themes/icon.css">
        <link rel="stylesheet" href="../public/css/zTreeStyle/zTreeStyle.css" type="text/css"></link>
        <script type="text/javascript" src="../public/js/jquery-1.8.0.min.js"></script>
        <script type="text/javascript" src="../public/js/upload2.js"></script>
        <script type="text/javascript" src="../public/js/jquery.form.js"></script>
        <script type="text/javascript" src="../public/jquery-easyui-1.4/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="../public/jquery-easyui-1.4/locale/easyui-lang-zh_CN.js"></script>
        <script type="text/javascript" src="../public/js/jquery.ztree.core-3.5.js"></script>
        <script type="text/javascript" src="../public/js/jquery.ztree.excheck-3.5.js"></script>
        <script type="text/javascript" src="../public/js/jquery.ztree.exedit-3.5.js"></script>
        <script type="text/javascript" src="../public/js/My97DatePicker/WdatePicker.js"></script>
        <script type="text/javascript" src="../public/echarts/echarts.min.js"></script>
    </head>
    <body leftmargin="0px" topmargin="0" rightmargin="0">
        <div id="mainListLayout" style="width: 100%; height: 100%;">
            <div data-options="region:'west',title:'日常安全检查'" style="width: 15%;padding-top: 8px;">
                <ul id="leftTree"></ul>
            </div>
            <div id="ctnMain" data-options="region:'center'" style="border:0px; ">
            </div>
        </div>
    </body>
<script type="text/javascript">
$(function(){
    initLayout();
    initTree();
});
function initLayout(){
    $('#mainListLayout').layout();
}
function initTree(){
    $('#leftTree').tree({
        url:'../every/findTree.do',
        onClick:function(node){
            showMain(node);
        }
    });
}

function showMain(node){
    if('安全检查信息管理'==node.text){
        changMainContext(node,'../every/findInfoMan.do');
    }
    else if('检查进度图'==node.text){
        changMainContext(node,'../every/findProgressMap.do');
    }

}
function changMainContext(node,action){
    $('#ctnMain').panel({    
        href:action
    });
}

function now(){
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth()+1;
    var day = date.getDate();
    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    return year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second;
}


</script>
</html>

正则

 (\s*<head>\s*)(.*\s*)*(</head>)

期望结果

 <head>
        <meta http-equiv="X-UA-Compatible" content="IE=8" />
        <title><%=CommonConstant.TEST_TITLE_CN%></title>
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
        <link rel="stylesheet" type="text/css" href="../public/css/style.css">
        <link rel="stylesheet" type="text/css" href="../public/jquery-easyui-1.4/themes/default/easyui.css">
        <link rel="stylesheet" type="text/css" href="../public/jquery-easyui-1.4/themes/icon.css">
        <link rel="stylesheet" href="../public/css/zTreeStyle/zTreeStyle.css" type="text/css"></link>
        <script type="text/javascript" src="../public/js/jquery-1.8.0.min.js"></script>
        <script type="text/javascript" src="../public/js/upload2.js"></script>
        <script type="text/javascript" src="../public/js/jquery.form.js"></script>
        <script type="text/javascript" src="../public/jquery-easyui-1.4/jquery.easyui.min.js"></script>
        <script type="text/javascript" src="../public/jquery-easyui-1.4/locale/easyui-lang-zh_CN.js"></script>
        <script type="text/javascript" src="../public/js/jquery.ztree.core-3.5.js"></script>
        <script type="text/javascript" src="../public/js/jquery.ztree.excheck-3.5.js"></script>
        <script type="text/javascript" src="../public/js/jquery.ztree.exedit-3.5.js"></script>
        <script type="text/javascript" src="../public/js/My97DatePicker/WdatePicker.js"></script>
        <script type="text/javascript" src="../public/echarts/echarts.min.js"></script>
    </head>

图片说明
在客户端的测试工具中可以匹配
但是在Eclipse和正则在线匹配工具中,一执行就会卡死

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • assange_h 2017-03-01 03:48
    已采纳
     (<head>.*?</head>)
    
    点赞 打赏 评论
  • assange_h 2017-03-01 03:47

    (

    .*?)
    试试这句话. 你的正则表达式可能出现了死循环.
    点赞 打赏 评论

相关推荐 更多相似问题