title: How do I use re.sub to remove a repeated block of text within square brackets?
body: <p>I have a response from an API that is a pseudo dictionary with some <code>'key':'values'</code> but mostly just a blob of text with <code>'key:values'</code>. I convert it with <code>.json()</code> to this:</p>
  <p><code>{'status': 'done', 'nextLogId': 'AQAAAXb', 'logs': [{'content': {'service': 't2pipeline', 'tags': ['tag1:value1', 'tag2:value2', 'tag3:value3'], 'timestamp': '2021-01-05T05:25:03.416Z', 'host': 'i-00e17', 'attributes': {'caller': 'psignal/state_machine.go:451', 'ts': 1609824303.416246, 'level': 'warn'}, 'message': 'psignal: Ignoring scte35 segmentation_descriptor (type:Program Start eventID:0 refUTC:Jan  5 05:25:02.387626333): there is an active segment with the same event_id'}, 'id': 'AQAAAXb'}, {'content': {'service': 't2pipeline', 'tags': ['tag1:value1', 'tag2:value2', 'tag3:value3'], 'timestamp': '2021-01-05T05:25:03.416Z', 'host': 'i-00e17', 'attributes': {'caller': 'psignal/state_machine.go:713', 't2': {'scte35': {'event_id': 0, 'event_ptr': '0xc009f32b40', 'seg_type_id': 16}}, 'ts': 1609824303.4161847, 'level': 'info'}, 'message': 'psignal: scte35 segdesc eventID:0 type:Program Start'}, 'id': 'AQAAAXb'}], 'requestId': 'OVZRd3hv'}</code></p>
  <p>There are two entries in here and in reality there will be more.</p>
  <p>I convert to a string with <code>json.dumps()</code></p>
  <p>And then use <code>re.sub()</code> to remove the <code>'tags': []</code>, section from the response and return the string like so</p>
  <pre class="lang-py prettyprint-override"><code>res = re.sub(r'&quot;tags&quot;: \[.*&quot;\],\s', &quot;&quot;, response_string)
  </code></pre>
  <p>The problem is it only return the last entry.</p>
  <pre class="lang-py prettyprint-override"><code>print(res)
  </code></pre>
  <p><code>{&quot;status&quot;: &quot;done&quot;, &quot;nextLogId&quot;: &quot;AQAAAXb&quot;, &quot;logs&quot;: [{&quot;content&quot;: {&quot;service&quot;: &quot;t2pipeline&quot;, &quot;timestamp&quot;: &quot;2021-01-05T05:25:03.416Z&quot;, &quot;host&quot;: &quot;i-00e17b8e872ec7d05&quot;, &quot;attributes&quot;: {&quot;caller&quot;: &quot;psignal/state_machine.go:713&quot;, &quot;t2&quot;: {&quot;scte35&quot;: {&quot;event_id&quot;: 0, &quot;event_ptr&quot;: &quot;0xc009f32b40&quot;, &quot;seg_type_id&quot;: 16}}, &quot;ts&quot;: 1609824303.4161847, &quot;level&quot;: &quot;info&quot;}, &quot;message&quot;: &quot;psignal: scte35 segdesc eventID:0 type:Program Start&quot;}, &quot;id&quot;: &quot;AQAAAXb&quot;}], &quot;requestId&quot;: &quot;OVZRd3hv&quot;}</code></p>
  <p>How do I modify the regex so that every instance of <code>'tags': []</code>, is removed and returns the whole string with all entries?</p>
  <p>Note: Since I can't <code>del</code> by key I think the only way to remove content is treating the response like a string and remove tag with regex.</p>