那每段话之前是什么条件?是空两格还是标签<p>

解决方案 »

  1.   

    var regex = /((\w+)(\b.*?\.))+/gvar paragraph = 'Any of the following. match variables can be used to identify. the most recent match and .the string from which it came. The match variables can be used in text replacement where the replacement string has to be determined dynamically.';var first_word_red = paragraph.replace(regex,'<font color=red>$2</font>$3');alert(first_word_red);
      

  2.   

    高手啊,可以实现,不过还有一个问题.当句号左右都没有空格的时候会显示不正常,可不可以在完善下.
    var paragraph = 'Any of the following.match variables can be used to identify. the most recent match and.the string from which it came.The match variables can be used in text replacement where the replacement string has to be determined dynamically.';
    你可以显示这个试下
      

  3.   

    chiny(从此有你)谢谢,还有假如句子是感叹句,或问句(即以!或?结尾).怎么处理.
      

  4.   

    var regex = /([^\b]\w+)(\b.*?\.)/gi;
    //句号'.'存在各种情况都有,包括重复的句号。
    var paragraph = 'Any of the following.'+ //左右没空格
    'match variables can be used to identify . .'+ //多余句号
    'the most recent match and . '+ //两边都有空格
    'the string from which it came .'+//左边空格
    'The match variables can be used in text replacement   .  '+//两边更多空格
    'where the replacement string has to be determined dynamically   .';
    //删除多余的句号
    var del_dot = paragraph.replace(/((\s*)[.](\s*))+/gi,'. ');
    var first_word_red = del_dot.replace(regex,'<font color=red>$1</font>$2');
    alert(first_word_red);
      

  5.   

    //[.!?]组成结尾字符类,你需要的话往[]中间加
    var regex = /([^\b]\w+)(\b.*?[.?!])/gi;
    //句号'.'存在各种情况都有,包括重复的句号。
    var paragraph = 'Any of the following.'+ //左右没空格
    'match variables can be used to identify . .'+ //多余句号
    'the most recent match and . '+ //两边都有空格
    'the string from which it came ?'+//左边空格
    'The match variables can be used in text replacement   !  '+//两边更多空格
    'where the replacement string has to be determined dynamically   .';
    //删除多余的标点符号
    var del_dot = paragraph.replace(/(\s*([.?!])\s*)+/gi,'$2 ');
    var first_word_red = del_dot.replace(regex,'<font color=red>$1</font>$2');
    alert(first_word_red);
    不过更多的细节你需要有一本参考书。