Regular expression to find string inside curly bra

2019-04-17 11:14发布

I am trying to get a substring which is inside curly brackets by using regular expression.

Assuming that I have the following string:

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

I'd like to be able to search for nice and cool

1条回答
倾城 Initia
2楼-- · 2019-04-17 12:14

Try as follows:

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

console.log(myString.match(pattern));
查看更多
登录 后发表回答