ut2
Version:
一个现代 JavaScript 实用工具库。[点击查看在线文档]。
19 lines (18 loc) • 680 B
TypeScript
/**
* 拆分字符串中的词为数组。
*
* @alias module:String.words
* @since 1.0.0
* @see {@link https://zh.wikipedia.org/wiki/ASCII ASCII}
* @param {string} string 要拆分的字符串。
* @param {RegExp | string} [pattern=/[^\x20-\x2f\x3a-\x40\x5b-\x60\x7b-\x7e]+/g] 匹配模式。默认 `/[^\x20-\x2f\x3a-\x40\x5b-\x60\x7b-\x7e]+/g`。
* @returns {string[]} 拆分后的数组。
* @example
*
* words('fred, barney, & pebbles'); // ['fred', 'barney', 'pebbles']
*
* words('fred, barney, & pebbles', /[^, ]+/g); // ['fred', 'barney', '&', 'pebbles']
*
*/
declare function words(string: string, pattern?: RegExp | string): string[];
export default words;