title: Find Text between x and y String in Javascript
body: <p>I have a node script that reads another js file, and I want to get the value of a specific variable in that js file. As I can imagine, there are way better solutions to solve exactly my problem, but I want a function, that I can use again later on, in for example web-apps.</p>
  
  <p>I need a function, that returns the string between a X string and a Y string. For example: </p>
  
  <pre><code>const string2searchin = "&lt;random text with unknown length&gt; /start/ i want to be selected /end/ &lt;random text with unknown length&gt;"
  </code></pre>
  
  <p>How can I get the string that is between "start" and "end"?
  The length of the random text it is between is not known.</p>
  
  <p>I've tried this:</p>
  
  <pre><code>var getText = (string, start, end) =&gt; {
      let arr = string.split("");
      let listen = false;
      let output = [];
  
      for(let el of arr){
          if(el == end &amp;&amp; listen) return output.toString();
          if(listen) output.push(el);
          if(el == start &amp;&amp; !listen) listen = true;
      }
  } 
  </code></pre>
  
  <p>It works just fine, but only with single characters. I want to have string with a length greater than 1 as a start and as an end.</p>