有字符串如下:
“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种情况都不要加"("和")"。
“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种情况都不要加"("和")"。
解决方案 »
- 今天小弟做了一个网站上线了,请大家多找BUG,在下感激不尽,谢谢了!
- 非常简单的问题,如何用js给一个文本框赋值????????????
- 如何在Mozilla中出发DIV 的onfocus事件
- 如何用javascript在页面之间传递参数
- 如何用jQuery 实现
- 两个js文件之间函数互相调用问题
- 怎样能够使OnMouseMove和OnClick事件都好使
- 如何用javascript判断客户端ie是否支持xslt的转换?
- 大家看看我的修改的一个关于右键菜单的程序,特别是,meizz(梅花雨)
- 我又来了,真不好意思?一个关于关闭窗口的问题?
- 搜索结果如何输出到iframe中去?
- jquery简单实例。代码找错。回帖有分
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
str = str.replace(/(.*)\band\b(\s+\bSlsmanDist\b\s+.*?)\band\b(.*)/img,"($1)or($2)or($3)");
alert(str);
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>