title: R sub/gsub replacing first occurence of match
body: <p>In R, I need to extract "Eight" from the following string:</p>
  
  <pre><code>this_str &lt;- " Eight years blah blah 50 blah blah, two years blah blah blah."
  </code></pre>
  
  <p>Here is my attempt using gsub:</p>
  
  <pre><code>gsub("^.*\\s([^ ]*)\\s(years|months)\\s.*", "\\1", this_str)
  </code></pre>
  
  <p>But this returns "two", which corresponds to the second occurrence of the pattern indicated in gsub(). In other posts it is said that sub() should return the first match. But when I use sub() it also gives "two".</p>