Obtain part of text in string that occurs before specified text
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4971961/javascript-truncate-string-before-comma">javascript Truncate string before comma</a>  </p>
</blockquote>



<p>In a javascript variable, a text (string) is stored...</p>

<pre><code>var maintext=" This is some random text. This is second sentence. This is third sentence.";
</code></pre>

<p>Now another variable stores a portion of text of the first variable as shown below</p>

<pre><code>var textportion="third sentence.";
</code></pre>

<p>Now, I want to obtain the text in variable 'maintext' that occurs just before text stored in 'textportion' variable... i.e. in this example, I want to obtain </p>

<pre><code>" This is some random text. This is second sentence. This is "
</code></pre>

<p>How do I obtain this? I would prefer pure JS, but use of libraries like jquery is also acceptable to me.</p>
