这个有写错误更正://匹配不含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);

解决方案 »

  1.   

    楼上的还是不对呀,我试了,含有s但不含有t的单词应该只有is,但现在的结果是this is 两个
      

  2.   

    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);
    就好了
      

  3.   

    按你给的字符串可以这样
    <script>
    var str='this is my dog';
    alert(str.match(/[^\Wt]+/g)||'没有匹配');
    </script>
      

  4.   

    刚刚没看到还要有个 s
    这样
    <script>
    var str='this is my dog';
    alert(str.match(/\b([^\Wt]*s)+\b/g)||'没有匹配');
    </script>
      

  5.   

    再次更正
    <script>
    var str='this is msy sog';
    alert(str.match(/\b([^\Wt]*s[^\Wt]*)+\b/g)||'没有匹配');
    </script>
      

  6.   

    /\s[a-su-z]{0,}[s][a-su-z]{0,}/g;这个怎样?
      

  7.   


    var str = "this is my dog ";
    var pattern = /\b(?=.*?s)(?!.*?t)\w+?\b/gi;
    var m = str.match(pattern);
    alert(m);