如果你不只是这3个标点符号: var s = "xxxooo& sdfsdf1,asdfssdfsd2。sdfgasdgasdg3?" //原来的存在漏洞:因为只考虑了, . ?符号, 未免有些欠妥 var match = /(\w+)\W/gi.exec(s); //用\w \W来替换 alert(match[1]); //xxxooo
亲们,一段中英文混着的字符串,想保留英文空格和标点,去掉中文空格保留标点,正则咋写。。 例如:“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.不要等明天交不上差再找借口,今天就要找好。”
var s = "xxxooo& sdfsdf1,asdfssdfsd2。sdfgasdgasdg3?" //原来的存在漏洞:因为只考虑了, . ?符号, 未免有些欠妥
var match = /(\w+)\W/gi.exec(s); //用\w \W来替换
alert(match[1]); //xxxooo
例如:“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.不要等明天交不上差再找借口,今天就要找好。”
谢谢,我去试下。