Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试合并一个splice这样的东西,它可以测试两件事:
splice
我该怎么做呢?即例如
var string = 'Special Place Co. (123 ABC)'
所以这会返回
'Special Place Co' [找到'。' 并删除拼接后]
谢谢
这是一个适合您的代码:
var string = 'Special Place Co. (123 ABC)'; if (string.length > 20) { string = string.substr(0,20); } string = string.replace(/([a-zA-Z0-9 ]+)(.*)/,'{$1}'); console.log(string);
http://jsfiddle.net/U5ZtU/