求助:用正则表达式实现“多关键字查找”及“反向比对”!

syhb 2005-06-26 01:53:53
1、
某N条字符串
a="hello,word. this is a test string.";
b="hello boy,i like you.";
n="...";

查询方法:hello like(与google,yahoo多关键字功能相同)
查询结果为B。

(使用符号 "|"即 hello|like查询两条都能找到,这不是我想要的。)

2、
a="hello,word. this is a test string.";
b="hello boy,i love you.";
c="boy,i like you.";

如何查找 不包含hello和love的字符串而找出C结果呢。


各位,在下谢过了。
...全文
149 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
orcale 2005-06-29
  • 打赏
  • 举报
回复
<script language='javascript'>
//條件成立的string返回True
a="hello,word. this is a test string.";
b="hello boy,i like you.";
n="...";
alert(b.match(/^.*hello{1,}.*like{1,}.*$/g)? true : false);


d="hello,word. this is a test string.";
e="hello boy,i love you.";
f="boy,i like you.";
alert(!f.match(/^.*(hello{1,}|love{1,}).*$/g)? true : false);
</script>
syhb 2005-06-27
  • 打赏
  • 举报
回复
我一点都看不懂,还是请哪位大哥大姐的帮帮忙啊。小弟真是拜求了!!!
netwar 2005-06-27
  • 打赏
  • 举报
回复
<script language="javascript">
<!--
var a=new Array();
a[0]="hello,word. this is a test string.";
a[1]="hello boy,i love you.";
a[2]="boy,i like you.";

//同时含有用笨方法,分开test,同时满足条件就打印
for(var i=0;i<a.length;i++){
var obj=a[i];
if(/hello/gi.test(obj)&&/love/gi.test(obj)){
alert(obj);
}
}
//-->
</script>
netwar 2005-06-27
  • 打赏
  • 举报
回复
<script language="javascript">
<!--
var a=new Array();
a[0]="hello,word. this is a test string.";
a[1]="hello boy,i love you.";
a[2]="boy,i like you.";

/*打印出不含有hello和love的字符串*/
for(i=0;i<a.length;i++){

if(/hello/.test(a[i])||/love/.test(a[i])){
continue;
}
alert(a[i]);
}
//-->
</script>
位流 2005-06-26
  • 打赏
  • 举报
回复
http://www.eob.cn/bbs/topic.asp?bbsid=1&forumid=9&topicid=437

看看吧,全了。

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧