如何按照提供的数组的顺序替换所有具有#sometext#的实例?
文本是一个字符串,我的目标是搜索所有我有一些文本被"#"性格然后按照数组的顺序用数组中的值替换这些实例
示例:
const text = "You are the #RANKED# highest ranked user (out of #TOTALUSER# people)"
const myArray = [10, 50];
搜索并替换后的文本应为:
"You are the 10 highest ranked user (out of 50 people)"
text.replace(/#([^#]+)#/g, _ => myArray.shift());