我只需要在空格后获得 2 个字符的缩写,这是示例
const string = "John Peter Don";
const result = string.match(/\b(\w)/g).join('');
console.log(result)// JPD->> i want only JP
尝试这个
const string = "John Peter Don";
const result = string.match(/(\b\S)?/g).join('').match(/(^\S|\S$)?/g).join('');
console.log(result);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句