TypeScript函数to():使用正则表达式分割字符串
function to(dte: string, chars: string[]): string[] {
const regex = new RegExp(`[${chars.join('')}]`, 'g');
return dte.split(regex);
}
使用示例:
const result = to('Hello, World!', [' ', ',']);
console.log(result); // Output: ['Hello', 'World!']
原文地址: https://www.cveoy.top/t/topic/pQIs 著作权归作者所有。请勿转载和采集!