title: Regex for parsing single key: values out of JSON in Javascript
body: <p>I'm trying to see if it's possible to lookup individual <code>keys</code> out of a <code>JSON</code> string in Javascript and return it's <code>Value</code> with <code>Regex</code>. Sort of like building a <code>JSON</code> search tool.</p>
  
  <p>Imagine the following JSON</p>
  
  <pre><code>"{
      "Name": "Humpty",
      "Age": "18",
      "Siblings" : ["Dracula", "Snow White", "Merlin"],
      "Posts": [
          {
              "Title": "How I fell",
              "Comments": [
                  { 
                      "User":"Fairy God Mother",
                      "Comment": "Ha, can't say I didn't see it coming"
                  }
              ]
          }
      ]
  }"
  </code></pre>
  
  <p>I want to be able to search through the <code>JSON</code> string and only pull out individual properties.</p>
  
  <p>lets assume it's a <code>function</code> already, it would look something like.</p>
  
  <pre><code>function getPropFromJSON(prop, JSONString){
      // Obviously this regex will only match Keys that have
      // String Values.
      var exp = new RegExp("\""+prop+"\"\:[^\,\}]*");
      return JSONString.match(exp)[0].replace("\""+prop+"\":","");    
  }
  </code></pre>
  
  <p>It would return the substring of the <code>Value</code> for the <code>Key</code>.</p>
  
  <p>e.g.</p>
  
  <pre><code>getPropFromJSON("Comments")
  
  &gt; "[
      { 
          "User":"Fairy God Mother",
          "Comment": "Ha, can't say I didn't see it coming"
      }
  ]"
  </code></pre>
  
  <p>If your wondering why I want to do this instead of using <code>JSON.parse()</code>, I'm building a JSON document store around <code>localStorage</code>. <code>localStorage</code> only supports key/value pairs, so I'm storing a <code>JSON</code> string of the entire <code>Document</code> in a unique <code>Key</code>. I want to be able to run a query on the documents, ideally without the overhead of <code>JSON.parsing()</code> the entire <code>Collection</code> of <code>Documents</code> then recursing over the <code>Keys</code>/nested <code>Keys</code> to find a match.</p>
  
  <p>I'm not the best at <code>regex</code> so I don't know how to do this, or if it's even possible with <code>regex</code> alone. This is only an experiment to find out if it's possible. Any other ideas as a solution would be appreciated. </p>