First next/previous substring positions in Javascript
<p>Let's say I have a long string, for instance:</p>

<pre><code>var sentence = "Marry had a little lamb, Peter had a little wolf, the wolf ate the little lamb and the little wolf was happy.";
</code></pre>

<p>I need to find the position of the substring "Peter" inside the string.</p>

<p>That, of course, is <code>var pos = sentence.indexOf("Peter");</code>.</p>

<p>But now I have a problem - I need to find the <em>last</em> occurrence of the substring "lamb" <code>before</code> <code>pos</code> and the <em>first</em> occurrence of the substring "wolf" <em>after</em> <code>pos</code>.</p>

<p>How do I do that? Pure Javascript please, no jQuery.</p>
