【问题标题】:Regular expression to find string inside curly brackets Javascript [duplicate]正则表达式在大括号内查找字符串Javascript [重复]
【发布时间】:2015-08-09 14:33:54
【问题描述】:

我正在尝试使用正则表达式获取大括号内的子字符串。

假设我有以下字符串:

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

我希望能够搜索nicecool

【问题讨论】:

  • \{([^}]*)\},问了很多次。或string.match(/[^{}]*(?=\})/g)
  • @AvinashRaj 大声笑太累了无法发布答案?? :-)

标签: javascript regex substring


【解决方案1】:

尝试如下:

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

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

【讨论】:

    猜你喜欢
    • 2019-07-31
    • 1970-01-01
    • 2015-08-26
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2021-11-05
    • 2012-04-05
    相关资源
    最近更新 更多