这个有写错误更正://匹配不含t、T的单词
var regex = /\s+([a-su-z]+)/gi;
// 显示带s、S的单词
var i = 0, word, words = 'this is my dog'.split(/\s+/);
while(word = words[i++]) if(/s/i.test(word)) alert(word);
var regex = /\s+([a-su-z]+)/gi;
// 显示带s、S的单词
var i = 0, word, words = 'this is my dog'.split(/\s+/);
while(word = words[i++]) if(/s/i.test(word)) alert(word);
换成
while(word = words[i++]) if(/s/i.test(word) && !/t/i.test(word)) alert(word);
就好了
<script>
var str='this is my dog';
alert(str.match(/[^\Wt]+/g)||'没有匹配');
</script>
这样
<script>
var str='this is my dog';
alert(str.match(/\b([^\Wt]*s)+\b/g)||'没有匹配');
</script>
<script>
var str='this is msy sog';
alert(str.match(/\b([^\Wt]*s[^\Wt]*)+\b/g)||'没有匹配');
</script>
var str = "this is my dog ";
var pattern = /\b(?=.*?s)(?!.*?t)\w+?\b/gi;
var m = str.match(pattern);
alert(m);