title: How to match string in between two words, but only the "closet" of the two words?
body: <p>I am new to regex, and am trying to capture a certain pattern. There are two words (name1 and host), that I want to capture everything in between, the problem is, sometimes "everything" in between might contain 'name1'. And if it does contain 'name1', it includes everything from the previous name1, to the next 'host' word. So I basically have two 'strings' from two different 'name1' being captured.</p>
  
  <p>This is the example I have:</p>
  
  <pre><code>name1{want-this-string}host,name1{want-this-string}host,name1{dont-want-this-string},name1{dont-want-this-either}name1{want-this-string}host
  </code></pre>
  
  <p>and this is the regex I'm using right now..</p>
  
  <pre><code>(?&lt;=\bname1\b).*?(?=\bhost\b)
  </code></pre>
  
  <p>My expected output is that it matches the 3 <code>{want-this-string}</code>, and not the <code>{dont-want-this}</code> stuff. so basically:</p>
  
  <pre><code>{want-this-string}{want-this-string}{want-this-string}
  </code></pre>
  
  <p>But right now its grabbing the first two <code>{want this string}</code> and then this whole section </p>
  
  <pre><code>{dont-want-this-string},name1{dont-want-this-either}name1{want-this-string}
  </code></pre>