<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>
<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>
<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>
<!--
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>
<!--
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>
//條件成立的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>