const str = "Hello, ${name}! You are ${age} years old."; const regex = /\$\{(\w+)\}/g; // 匹配大括号内的单词字符 const matches = str.match(regex).map((item)=>item.slice(1,-2)); // 获取匹配结果数组 const params = []; // 用于存储参数和对应的值 matches console.log(matches)