title: Is there a way to find a specific word multiple times, then find related words near that word?
body: <p>I have the below and I am looking for a way to find the word &quot;pizza&quot; as many times no matter how many words are in between.</p>
  <p>Then find related words (e.g. pepperoni, large) only if NEAR the word &quot;pizza&quot;</p>
  <p>I tried using a larger character count on f1 {0,100} but it seems to carry over and ignore the {0,50} I have for near words</p>
  <pre><code>import re
  
  string = ['I need a pizza with pepperoni word word word word word word word and a small pizza']
  
  for s in string:
      f1 = re.findall(r'(\b(pizza|pie|pizzeria)\b)',s, re.IGNORECASE)
      if f1:
  
          f2 = re.findall(r'(.{0,50}\b(pepperoni|cheese|sausage)\b.{0,50})',f1[0][0], re.IGNORECASE)
          if f2:
              print(&quot;what size?&quot;)
  
          f3 = re.findall(r'(.{0,50}\b(small|medium|large)\b.{0,50})',f1[0][0], re.IGNORECASE)
          if f3:
              print(&quot;what toppings?&quot;)
  
          if not f2 and not f3:
              print(&quot;what size and toppings?&quot;)
  </code></pre>