日期:2014-05-17 浏览次数:20403 次
function getString(str, param){ var reg = new RegExp("\\" + param + "\\d+\\.\\d+", "g"); return str.replace(reg, ""); }
------解决方案--------------------
var str = "|12,12.0|13,12.0|14,11.12|"; function testReplace(_str) { var reg=new RegExp('\\'+_str+'\\d+\\.\\d+','g'); console.log(str.replace(reg,'')); } testReplace('|12,');
------解决方案--------------------
var str = "|12,12.0|13,12.0|14,11.12|";
function testReplace(_str)
{
var reg=new RegExp('\\'+_str+'\\d+(\\.\\d+)?','g');
console.log(str.replace(reg,''));
}
testReplace('|12,');
------解决方案--------------------
"\\" + param + "\\d+(\\.\\d+)?"
或者干脆
"\\" + param + "[^\|$]+"
------解决方案--------------------
<script type="text/javascript"> function test(s) { var str = "|12,12.0|13,12.0|14,11.12|"; var reg = new RegExp('\\' + s + '[^|]*', 'g'); alert(str.replace(reg, '')); } test('|13,'); </script>