title: Troubles with regexp in R: Match word surrounded by whitespace or start/end of string
body: <p>I want to count the number of words from a dictionary that appear in a string if it is surrounded by whitespace or it is at the start or end of the string.</p>
  
  <p>I'm using <a href="https://stackoverflow.com/a/13225891/4462566">this</a> answer like this:</p>
  
  <pre><code>library(stringi)
  
  testStr &lt;- c("dutch dutch brown", "brown ", "AAdutch", "dutchAA", "AAbrown",
               "brownAA", "hello")
  stri_count_regex(testStr, "(^|\\s+)dutch|brown(\\s+|$)")
  </code></pre>
  
  <p>Which returns <code>3 1 0 1 1 0 0</code>, but I'm expecting <code>3 1 0 0 0 0 0</code>. So the problem is that it also counts <code>"dutchAA"</code> and <code>"AAbrown"</code> which I don't want.</p>
  
  <p>I'm a bit puzzled about this, as this regular expression works fine when I run it on <a href="http://regexr.com/" rel="nofollow noreferrer">RegExr</a>.</p>