title: How do I match n words in a regex?
body: <p>After scratching my head and extensive googling, I can't seem to get this right.</p>
  
  <p>I have this sample string:</p>
  
  <blockquote>
    <p>test = "true sales are expected to be between 50% and 60% higher than
    those reported for the previous corresponding year. the main reason is
    blah blah. the fake sales are expected to be in the region of between
    25% and 35% lower."</p>
  </blockquote>
  
  <p>I'm trying to determine whether the 'true' sales where higher or lower. Using <code>R</code>, and the 'stringr' library, I'm trying it as follows:</p>
  
  <pre><code>test = "true sales are expected to be between 50% and 60% higher than those reported for the previous corresponding year. the main reason is blah blah. the fake sales are expected to be in the region of between 25% and 35% lower."
  positive.regex = "(sales).*?[0-9]{1,3}% higher"
  negative.regex = "(sales).*?[0-9]{1,3}% lower"
  </code></pre>
  
  <p>Which yields the following results:</p>
  
  <blockquote>
    <p>str_extract(test,positive.regex)
        [1] "sales are expected to be between 50% and 60% higher"
    str_extract(test,negative.regex)
        [1] "sales are expected to be between 50% and 60%
        higher than those reported for the previous corresponding year. the main reason is blah blah. the fake sales are expected to be in the region of between 25% and 35% lower"</p>
  </blockquote>
  
  <p>I'm trying to find a way to limit the number of words matched between (sales) and <code>'% higher'</code> or <code>'% lower'</code>, so that the negative regex won't match. i.e I know I need to replace '.*?' with something that matches whole words, not characters, and limit the number of these words to something like 3-5, how can I do this?</p>