a.*?b
就是 a
開始 b
結束的匹配
若是要限制是一行的開頭和末尾的話,就是 ^a.*?b$
javascript
原字符java
aaa javascript:LUI.pageOpen('/ekp/sys/profile/index.jsp#app/ekp/km/review','_blank'); ccc
或者app
aaa javascript:LUI.pageOpen('/ekp/sys/profile/index.jsp#app/ekp/sys/task','_blank'); ccc
須要替換成 aaa bbb ccccurl
<script type="text/javascript"> var item = "aaa javascript:LUI.pageOpen('/ekp/sys/profile/index.jsp#app/ekp/km/review','_blank'); ccc"; // var item = aaa javascript:LUI.pageOpen('/ekp/sys/profile/index.jsp#app/ekp/sys/task','_blank'); ccc var curl = window.location.href; var replaceText = "javascript:showTipWindow('"+curl+"');"; var result = item.replace(/javascript:LUI.pageOpen\(\'\/.*sys\/profile.*?_blank\'\);/,replaceText); document.write(result); window.showTipWindow = function(url){ alert(url); } </script>