// https://stackoverflow.com/a/73891404 /** 文本正则替换的,异步版本 */ export async function textReplaceAsync( string: string, regexp: RegExp, replacerFunction: (...args: any[]) => Promise ) { const replacements = await Promise.all(Array.from(string.matchAll(regexp), (match) => replacerFunction(...match))) let i = 0 return string.replace(regexp, () => replacements[i++]) }