我试图通过使用正则表达式来获取大括号内的子串。
假设我有以下字符串:
"This is a {nice} text to search for a {cool} substring".
我希望能够搜索nice
和cool
答案 0 :(得分:1)
尝试如下:
var myString = "This is a {nice} text to search for a {cool} substring",
pattern = /[^{}]*(?=\})/g;
console.log(myString.match(pattern));