title: get string between two strings with javascript
body: <p>How do I get a string between two strings using match with variables?  The following code works well if I use match with strings <a href="https://stackoverflow.com/questions/5642315/regular-expression-to-get-a-string-between-two-strings-in-javascript">Regular Expression to get a string between two strings in Javascript</a>  I also tried to apply the info at <a href="https://stackoverflow.com/questions/3172985/javascript-use-variable-in-string-match">JavaScript - Use variable in string match</a> :</p>
  
  <pre><code>var test = "My cow always gives milk";
  
  var testRE = test.match("cow(.*)milk");
  alert(testRE[1]);
  </code></pre>
  
  <p>But what if I have:</p>
  
  <pre><code>var firstvariable = "cow";
  var secondvariable = "milk";
  
  var test = "My cow always gives milk";
  </code></pre>
  
  <p>I've tried various things including:</p>
  
  <pre><code>var testRE = test.match("firstvariable(.*)secondvariable");
  alert(testRE[1]);
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>var testRE = testRE.match + '("' + firstvariable + "(.*)" + secondvariable +'")';
  alert(testRE[1]);
  </code></pre>
  
  <p>Neither worked.   </p>