有字符串如下:
“LeftMessage is null and SentEmail is null and MetWith is null and SlsmanDist like 'KEE - kevin tang%”先检索出有SlsmanDist这个单词,
1.如果SlsmanDist前的and是最后一个and
将其前面的"and"改为" )OR",并且在头部加(
其它的and不变,字符串长度是可变的
如:
“(LeftMessage is null and SentEmail is null and MetWith is null) or SlsmanDist like 'KEE - kevin tang%”2.如果SlsmanDist后面还有and:
如:
“SentEmail is null and MetWith is null and SlsmanDist like 'KEE - kevin tang% and LeftMessage is null and zinc”
将其前面和后面的第一个"and"分别 改为") or" ,"or (",并且将开始和结尾都加"(",")";

“(SentEmail is null and MetWith is null ) or SlsmanDist like 'KEE - kevin tang% or (LeftMessage is null and zinc)”
3.如果SlsmanDist就是第一个单词,那么将其后面的的"and"改为"or (",结尾加")";
但是如果SlsmanDist前后都没有and,那么3种情况都不要加"("和")"。

解决方案 »

  1.   

    其实其他的过程都实现了,只是SlsmanDist中间时,它后面出现的第一个and改为or,也就是情况2
      

  2.   

    郁闷啊,说的更简单点,就是一段字符串,检测里面是否有个SlsmanDist单词,如果有将其后的出现的第一个and改为or
      

  3.   


    var s = "SentEmail is null and MetWith is null and SlsmanDist like 'KEE - kevin tang% and LeftMessage is null and zinc";
    var rexL = /^([\w\W\s\S\.]*)(and)([\w\W\s\S\.]*)\s*(?=SlsmanDist)/img;
    var rexR = /([\w\W\s\S\.]*SlsmanDist[\w\W\s\S\.]*?)(and)([\w\W\s\S\.]*$)/img;
    s = s.replace(rexL,function($0,$1,$2,$3){
    return '(' + $1 + ' ) OR' + $3;
    }
    );
    s = s.replace(rexR,function($0,$1,$2,$3){
    return $1 + ' OR (' + $3 + ')';
    }
    );
    alert(s);不知是否是你想要的结果:D
      

  4.   

    var str = "SentEmail is null and MetWith is null and SlsmanDist like 'KEE - kevin tang% and LeftMessage is null and zinc";
    str = str.replace(/(.*)\band\b(\s+\bSlsmanDist\b\s+.*?)\band\b(.*)/img,"($1)or($2)or($3)");
    alert(str);
      

  5.   

    <script>
    var str="SentEmail is null and MetWith is null and SlsmanDist like 'KEE - kevin tang% and LeftMessage is null and zinc";
    str=str.replace(/^(.*)and(.*?SlsmanDist.*?)and(.*)$/i,"($1) or $2 or ($3)");
    alert(str);
    </script>