首页 > 解决方案 > 在大括号之间获取,包括第一个和最后一个大括号

问题描述

我有的代码:

点击这里查看代码

我想在(包括)第一个花括号到最后一个(包括)之间:

<html lang=3D"pl-US"> <head> </head> <body> <div>  <script data-scope=3D"in=
boxmarkup" type=3D"application/json">{
  "api_version": "1.0",
  "publisher": {
    "api_key": "61d9",
    "name": "Google Alerts"
  },
  "entity": {
    "external_key": "Google Alert - Adidas"
  },
  "updates": {
    "snippets": [ {
      "icon": "BOOKMARK",
      "message": "lala (Nike)"
    } ]
  },
  "cards": [ {
    "title": "Google Alert - Adidas",
    "subtitle": "Nike and Adidas",
    "actions": [ {
      "name": "Sam",
      "url": "https://www.google.com"} ],
    "widgets": [ {
      "type": "LINK",
      "title": "lala (Nike)"
    } ]
  } ]
}
</script> <!--[if mso]>
 <table><tr><td width=3D650>
<![endif]-->

当我使用\{([^()]|())*\}时,它返回给我一个不包括所有的奇怪的东西(如代码所示)。计划是解析数据并用作 JSON。

我只需要(包括)第一次出现{和最后一次出现}.

标签: javascriptregex

解决方案


推荐阅读