Skip to content

Instantly share code, notes, and snippets.

@mybedhome
Created April 22, 2023 12:37
Show Gist options
  • Save mybedhome/7550d63ed1b8913b451a6daa8f4ae86b to your computer and use it in GitHub Desktop.
Save mybedhome/7550d63ed1b8913b451a6daa8f4ae86b to your computer and use it in GitHub Desktop.
匹配字符串${}括号里的内容
const str = '{"a": "${默认:发起人}", "b": "${點认:组织}", "c": "${默认: 标题}"}';
const regex = /\$\{([^}]+)\}/g;
const matches = str.match(regex);
console.log(matches); // 输出 ["${默认:发起人}", "${點认:组织}"]
const str2 = matches.join("");
console.log(str2)
const regex2 = /[^\$\{\}]+/g;
const matches2 = str2.match(regex2);
console.log(matches2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment