title: Get string between 2 words, that contain this words inside him too
body: <p>I have strings, and i want to find in them 2 words: '<strong>start</strong>' and '<strong>end</strong>'. </p>
  
  <p>'<strong>start</strong>' and '<strong>end</strong>' always come together (maybe i will have another characters between them, but if i have '<strong>start</strong>', i will have '<strong>end</strong>' too).</p>
  
  <p>I try to do with regEx source that find the first '<strong>start</strong>' and than his own '<strong>end</strong>', and it will return the correct substring.</p>
  
  <hr>
  
  <p>examples of strings: <em>[i wrote in this examples index for every couple of 'start' and 'end' <strong>just for clarity</strong> (in the real strings i will not have this indexes)- the answer always between index (1)]</em></p>
  
  <ol>
  <li>something <strong>start</strong> something_needed <strong>end</strong> something <code>// print 'something_needed'</code></li>
  <li><strong>start</strong>(1) something start(2) something end(2) something <strong>end</strong>(1) start  something end <code>// print 'something start(2) something end(2) something'</code></li>
  <li><strong>start</strong>(1) something start(2) start(3) something end(3) something start(4) end(4) something end(2) something <strong>end</strong>(1) something start(5) something end(5) <code>// print 'something start**(2) start(3) something end(3) something start(4) end(4) something end(2) something'</code></li>
  </ol>
  
  <hr>
  
  <p>This is my solution in Javascript, but i prefer the answer in regEx only.</p>
  
  <p>i find all the <strong>start</strong>, and after that all the <strong>end</strong>, and than- for every <strong>start</strong>: count++, for every <strong>end</strong>: count--. when count == 0, it the position of the correct <strong>end</strong>.</p>
  
  <pre><code>function getStartEnd(str) {
      str = " "+str+" ";
      var start = matchPosArr(str, /[\d\s\r\n,\(\)\[\]\{\}]+START+(?=[\d\s\r\n,\(\)\[\]\{\}])/gi);
      var end = matchPosArr(str, /[\d\s\r\n,\(\)\[\]\{\}]+END+(?=[\d\s\r\n,\(\)\[\]\{\}])/gi);
      var count = 0;  // counter
      var si = 0;     // index of start array
      var ei = 0;     // index of end array
      var isStart = false;
      while (true) {
          if (ei &gt;= end.length) {
              alert('error');
              break;
          }
          else if (si &gt;= start.length) {
              ei++;
              count--;
              if (count == 0) {
                  ei--;
              }
          }
          else if (start[si] &gt; end[ei]) {
              ei++;
              count--;
          }
          else if (start[si] &lt; end[ei]) {
              si++;
              count++;
          }
          if (count == 0 &amp;&amp; isStart==true) {
              break;
          }
          isStart = true;
      }
      return str.substring(start[0]+("start ".length),end[ei]);
  }
  function matchPosArr(str, regEx) {
      var pos = []; 
      while ((match = regEx.exec(str)) != null) {
          pos.push(match.index);
      }
      return pos;
  }
  
  alert( getSelectFrom(str) );
  </code></pre>