那每段话之前是什么条件?是空两格还是标签<p>
解决方案 »
- 求教如何动态加载脚本到HTML?吐槽javascript这语言真弱智
- 此段代码的应用场景是什么,烦请高手举个实例?
- jquery formvalidator 如何用在多个form上? 急
- IE8下不能正常预览图片,请高手帮忙,急!!!
- [求助]java做图形界面的一个小白错误,检查不出来了。。
- javascript 如何控制excel生成chart图?
- 请问xmlhttp对象和xmldom对象在使用上有什么区别
- 怎么样让弹出的窗口的关闭按扭变灰色?
- 升星了,散分,向两顆星挺进
- 如何用Javascript 生成树并在点击节点时得到其子节点?
- 这么简单的js怎么不对呢???
- 为什么同一个函数里的document不一样?这个动作该如何写?
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 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);
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);
不过更多的细节你需要有一本参考书。