结论
a.*?b
就是 a
开始 b
结束的匹配
如果要限制是一行的开头和末尾的话,就是 ^a.*?b$
实例
原字符
aaa javascript:LUI.pageOpen('/ekp/sys/profile/index.jsp#app/ekp/km/review','_blank'); ccc
或者
aaa javascript:LUI.pageOpen('/ekp/sys/profile/index.jsp#app/ekp/sys/task','_blank'); ccc
需要替换成 aaa bbb ccc
<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>