JavaScript - Extract JSON from log file
<p>I need to extract JSON string (which will be used later to parse JSON) from a log file. The file is in this format:</p>

<pre><code>[16:11:20] some text
[16:11:20] some text
some text
some text
[
  {
    "description": "some text",
    "elements": [{
        "id": "some text",
        "keyword": "some text",
        "line": 20,
        "name": "some text",
        "steps": [{
            "arguments": [],
            "keyword": "some text ",
            "result": {
                "status": "passed",
                "duration": 14884761888
            },
            "hidden": true,
            "match": {
                "location": "some text"
            }
        },
        {
            "arguments": [],
            "keyword": "sometext ",
            "name": "sometext",
            "result": {
                "status": "passed",
                "duration": 463674
            },
            "line": 11,
            "match": {
                "location": "sometext"
            }
        }
        ],
        "tags": [
          {
            "name": "@sometext-no",
            "line": 7
          },
          {
            "name": "@sometext",
            "line": 8
          }
        ],
        "type": "sometext"
      }

    ],
    "id": "sometext",
    "keyword": "sometext",
    "line": 1,
    "name": "sometext",
    "tags": [],
    "uri": "sometext"
  }
][16:11:54] some text
[16:11:54] some text
</code></pre>

<p>How can I construct a regex in JavaScript which will extract JSON data from this file so that it can be used by string.match() to give the desired output</p>

<p>The pattern I am trying is as below</p>

<pre><code>var regExtract = /(\[\s+\{[\s\S]*\}\s+\]\s+\}\s+\]\s+\}\s+\])/;
var matchedJson = data.toString().match(regExtract)[1];
</code></pre>