js 正则表达式 截取一段话,只要标点符号前面的字 比如 , 。 ? 等等

thethird1 2013-12-04 10:19:41
js 正则表达式 截取一段话,只要标点符号前面的字 比如 , 。 ? 等等 怎么操作 望牛人不吝指教! 小弟拜谢了
...全文
1059 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
走在四季 2015-02-27
  • 打赏
  • 举报
回复
引用 7 楼 xzy21com 的回复:
[quote=引用 6 楼 u011098115 的回复:] 亲们,一段中英文混着的字符串,想保留英文空格和标点,去掉中文空格保留标点,正则咋写。。 例如:“Never put off the work till tomorrow what you can put off today.不要 等 明天 交不上 差再找借口, 今天就要找好。”; 替换成“Never put off the work till tomorrow what you can put off today.不要等明天交不上差再找借口,今天就要找好。”
str.replace(/\s+(?=[\u2E80-\u9FFF]+)/g,"")[/quote]
引用 7 楼 xzy21com 的回复:
[quote=引用 6 楼 u011098115 的回复:] 亲们,一段中英文混着的字符串,想保留英文空格和标点,去掉中文空格保留标点,正则咋写。。 例如:“Never put off the work till tomorrow what you can put off today.不要 等 明天 交不上 差再找借口, 今天就要找好。”; 替换成“Never put off the work till tomorrow what you can put off today.不要等明天交不上差再找借口,今天就要找好。”
str.replace(/\s+(?=[\u2E80-\u9FFF]+)/g,"")[/quote] 谢谢,我去试下。
scscms太阳光 2015-02-27
  • 打赏
  • 举报
回复
引用 6 楼 u011098115 的回复:
亲们,一段中英文混着的字符串,想保留英文空格和标点,去掉中文空格保留标点,正则咋写。。 例如:“Never put off the work till tomorrow what you can put off today.不要 等 明天 交不上 差再找借口, 今天就要找好。”; 替换成“Never put off the work till tomorrow what you can put off today.不要等明天交不上差再找借口,今天就要找好。”
str.replace(/\s+(?=[\u2E80-\u9FFF]+)/g,"")
走在四季 2015-02-26
  • 打赏
  • 举报
回复
亲们,一段中英文混着的字符串,想保留英文空格和标点,去掉中文空格保留标点,正则咋写。。 例如:“Never put off the work till tomorrow what you can put off today.不要 等 明天 交不上 差再找借口, 今天就要找好。”; 替换成“Never put off the work till tomorrow what you can put off today.不要等明天交不上差再找借口,今天就要找好。”
thethird1 2013-12-04
  • 打赏
  • 举报
回复
OK 谢谢
似梦飞花 2013-12-04
  • 打赏
  • 举报
回复
m[0]就试了吧
thethird1 2013-12-04
  • 打赏
  • 举报
回复
亲 只截取第一个标点符号之前的文字 剩下的就不要了
打字员 2013-12-04
  • 打赏
  • 举报
回复

	var s = "sdfsdf1,asdfssdfsd2。sdfgasdgasdg3?"
	var m = s.match(/[^,。?]+(?=[,。?])/g);
	alert(m);
thy442030800 2013-12-04
  • 打赏
  • 举报
回复
如果你不只是这3个标点符号:

var s = "xxxooo& sdfsdf1,asdfssdfsd2。sdfgasdgasdg3?"    //原来的存在漏洞:因为只考虑了, . ?符号, 未免有些欠妥
var match = /(\w+)\W/gi.exec(s);    //用\w \W来替换
alert(match[1]); //xxxooo

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧