日期:2014-05-16  浏览次数:20615 次

关于replace替换指定位置的单词
有字符串
“LeftMessage is null and SentEmail is null and MetWith is null and SlsmanDist like 'KEE - kevin tang%”

先检索出有SlsmanDist这个单词,
如果有,将其前面的and改为OR,
其它的and不变,字符串长度是可变的

------解决方案--------------------
JScript code
var test = "LeftMessage is null and SentEmail is null and MetWith is null and SlsmanDist like 'KEE - kevin tang";

    alert(test.replace(/and SlsmanDist/g, function() {
            return "or SlsmanDist";
        }));

------解决方案--------------------
JScript code
var str="LeftMessage is null and SentEmail is null and MetWith is null and SlsmanDist like 'KEE - kevin tang%";
alert(str.replace(/and\s+(SlsmanDist)/gi,"Or $1"))

------解决方案--------------------
JScript code
var str = "LeftMessage is null and SentEmail is null and MetWith is null and  SlsmanDist";
alert(str.replace(/\band\b(?=\s*\bSlsmanDist\b)/img,"OR"));

------解决方案--------------------
看了上面几位,我不敢发言了...

------解决方案--------------------
探讨

JScript code
var str="LeftMessage is null and SentEmail is null and MetWith is null and SlsmanDist like 'KEE - kevin tang%";
alert(str.replace(/and\s+(SlsmanDist)/gi,"Or $1"))