title: mySql retrieving data between square brackets
body: <p>I have strings of data in a field named <code>content</code>, one record may look something like:</p>
  
  <pre><code>loads of text ... [attr1] some text [attr2] more text [attr3] more text etc...
  </code></pre>
  
  <p>What I'm looking to do is get all the text within the square brackets; so that I can put it into a PHP array. Is this even possible with mySql?</p>
  
  <p>I've seen the following post: <a href="https://stackoverflow.com/questions/8072402/looking-to-extract-data-between-parentheses-in-a-string-via-mysql">Looking to extract data between parentheses in a string via MYSQL</a>, but they are looking to only extract one value from between their parentheses, I have an unknown number of them. After reading that post I've though of doing something like the following;</p>
  
  <pre><code>SELECT substr(content,instr(content,"["), instr(content,"]")) as attrList from myTable
  </code></pre>
  
  <p>Which would grab me the following:</p>
  
  <pre><code>[attr1] some text [attr2] some more text [attr3]
  </code></pre>
  
  <p>and I can use PHP to strip the rest of the text out and then explode the string into an array, but is there a better way to do this just using mySql where I can retrieve something like:</p>
  
  <pre><code>[attr1][attr2][attr3]
  </code></pre>
  
  <p>I was thinking perhaps regex, but I see that just returns a true of false which doesn't help me a lot.</p>