title: Pattern Matching using Grep and/or RegEx to Extract ID from metadata field in R
body: <p>I have metadata strings that look like this:</p>
  
  <pre><code>{\"vote\":\"com.jivesoftware.community.acclaim.impl.VoteImpl@8b6b31f7\",\"referringSource\":null,\"referringUser\":null,\"acclaim\":\"AcclaimImpl{acclaimID=3146, object=EntityDescriptor{objectID=1900, objectType=102}, acclaimType='like', visibility=true, creationDate=Mon Jul 13 11:52:18 PDT 2014, modificationDate=Mon Jul 13 11:52:18 PDT 2014, properties={}}\",\"create\":true} 
  </code></pre>
  
  <p>and I need to extract the <code>objectID</code>. I've been trying to use pattern matching, but I keep getting either</p>
  
  <ol>
  <li>No matches</li>
  <li>The entire metadata returned to me, or</li>
  <li>Unexpected results</li>
  </ol>
  
  <p>For example, I create this object for a simple test:</p>
  
  <pre><code>testme &lt;- "{\"vote\":\"com.jivesoftware.community.acclaim.impl.VoteImpl@8b6b31f7\",\"referringSource\":null,\"referringUser\":null,\"acclaim\":\"AcclaimImpl{acclaimID=3246, object=EntityDescriptor{objectID=1400, objectType=102}, acclaimType='like', visibility=true, creationDate=Mon Jul 14 11:52:18 PDT 2014, modificationDate=Mon Jul 14 11:52:18 PDT 2014, properties={}}\",\"create\":true}"
  </code></pre>
  
  <p>and I try the following, which seems to work fine when I create and test it in a program called <code>RegEx Magic</code>, with my version of R specified in that program:</p>
  
  <pre><code>grep("\\AobjectID=[0-9]+[[:&gt;:]]\\z", testme, perl=TRUE, value=TRUE);
  </code></pre>
  
  <p>yet the result I get is:</p>
  
  <pre><code>character(0)
  </code></pre>
  
  <p>I've tried some simpler approaches, such as:</p>
  
  <pre><code>regexpr(pattern="\\&lt;objectID=[0-9]{1,4}", testme, useBytes = FALSE, fixed = TRUE)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>regexpr(pattern="\\bobjectID=[0-9]", testme, useBytes = FALSE)
  </code></pre>
  
  <p>and those lead to the unexpected results (i.e. I'm not sure what it's giving me, but it's not what I'm looking for):</p>
  
  <pre><code>[1] -1
  attr(,"match.length")
  [1] -1
  attr(,"useBytes")
  [1] TRUE
  </code></pre>
  
  <p>or</p>
  
  <pre><code>[1] 176
  attr(,"match.length")
  [1] 10
  attr(,"useBytes")
  [1] TRUE
  </code></pre>
  
  <p>, respectively. If I remove the <code>\\b</code> or <code>\\&lt;</code> then it returns the entire metadata string.</p>
  
  <p>Could someone help me figure this out? Thanks in advance.</p>