title: Split Out Shortcode Bracket from JSON Array Bracket With Compatibility
body: <p>Generally, I have a hard time with regex patterns beyond basic matching. I have a simplistic shortcode parser similar to how Wordpress has so an example is:</p>
  
  <pre><code>~PLUGIN::name_of_plugin["param1"="value1","param2"="value2"]~
  </code></pre>
  
  <p>I have this splitting and working, I just use <code>explode()</code> on the <code>[</code> and trim the <code>]</code> to get the parameters portion. Now, I want to pass a nested array so I am trying to do a JSON object into those brackets instead, so the string to parse would look like this:</p>
  
  <pre><code>$str    =   '~PLUGIN::name_of_plugin[{
              "category":"whatever",
              "test":[{
                      "name":"Title Something",
                      "desc":"123123-A",
                      "result":"Confirmation",
                      "conforms":"true",
                      "mass_spec":"true"
                  }]
          }]~';
  </code></pre>
  
  <p>After a series of different pattern attempts with varying degrees of success, this is what I came up with that I would consider <em>useable</em>:</p>
  
  <pre><code>preg_match('/^\~([a-z]+::)([a-z\_\-]+)([^\~]+)\~/i',$str,$match);
  print_r($match);
  </code></pre>
  
  <p>It matches to this (I can trim key <code>3</code> for what I need):</p>
  
  <pre><code>Array
  (
      [0] =&gt; ~PLUGIN::name_of_plugin[{
                  "category":"whatever",
                  "test":[{
                          "name":"Title Something",
                          "desc":"123123-A",
                          "result":"Confirmation",
                          "conforms":"true",
                          "mass_spec":"true"
                      }]
              }]~
      [1] =&gt; PLUGIN::
      [2] =&gt; name_of_plugin
      [3] =&gt; [{
                  "category":"whatever",
                  "test":[{
                      "name":"Title Something",
                      "desc":"123123-A",
                      "result":"Confirmation",
                      "conforms":"true",
                      "mass_spec":"true"
                  }]
              }]
  )
  </code></pre>
  
  <p>The problem there is, if the shortcode doesn't have parameters like:</p>
  
  <pre><code>$str    =   '~PLUGIN::name_test~';
  </code></pre>
  
  <p>It splits out to this (notice the <code>n</code> in key <code>3</code>):</p>
  
  <pre><code>Array
  (
      [0] =&gt; ~PLUGIN::name_of_plugin~
      [1] =&gt; PLUGIN::
      [2] =&gt; name_of_plugi
      [3] =&gt; n
  )
  </code></pre>
  
  <p>Is there some sort of forward-looking thing I should be doing that would make this split out to:</p>
  
  <pre><code>Array
  (
      [0] =&gt; ~PLUGIN::name_of_plugin~
      [1] =&gt; PLUGIN::
      [2] =&gt; name_of_plugin
  )
  </code></pre>
  
  <p>but also will split the parameters block out when it exists? I am trying not to do some sort of hack where I <code>implode()</code> key <code>2</code> and <code>3</code> or something.</p>