正则表达式在花括号Javascript中查找字符串

时间:2015-05-27 13:15:37

标签: javascript regex substring

我试图通过使用正则表达式来获取大括号内的子串。

假设我有以下字符串:

"This is a {nice} text to search for a {cool} substring".

我希望能够搜索nicecool

1 个答案:

答案 0 :(得分:1)

尝试如下:

var myString = "This is a {nice} text to search for a {cool} substring",
    pattern = /[^{}]*(?=\})/g;

console.log(myString.match(pattern));