title: Extract occurrence of text between brackets from a text file Python
body: <p>Log file:</p>
  
  <pre><code>INFO:werkzeug:127.0.0.1 - - [20/Sep/2018 19:40:00] "GET /socket.io/?polling HTTP/1.1" 200 -
  INFO:engineio: Received packet MESSAGE, ["key",{"data":{"tag1":12,"tag2":13,"tag3": 14"...}}]
  </code></pre>
  
  <p>I'm interested in extracting only the text from with in the brackets which contain the keyword <code>"key"</code> and not all of the occurrences that match the regex pattern from below.</p>
  
  <p>Here is what I have tried so far:</p>
  
  <pre><code>import re
  with open('logfile.log', 'r') as text_file:
      matches = re.findall(r'\[([^\]]+)', text_file.read())
      with open('output.txt', 'w') as out:
          out.write('\n'.join(matches))
  </code></pre>
  
  <p>This outputs all of the occurrences that match the regex. The desired output to the output.txt would look like this:</p>
  
  <blockquote>
  <pre><code>"key",{"data":{"tag1":12,"tag2":13,"tag3": 14"...}}
  </code></pre>
  </blockquote>