Is there any way to return the thrown away part of the split operation?
<p>I'm building a basic application which lets the user to share or continue their search status between sessions with # parameters in Javascript (I'm building this as a SPA so GET parameters won't always necessarily work).</p>

<p>In my app I could have a URI like: <code>/items#rarity=rare,common,uncommon&amp;cost=ascending&amp;category=primary</code></p>

<p>If I wanted to check what state to set the cost filter in my react component, I'd want to extract <code>asecnding</code> and then check the ascending checkbox to set the state on page load.</p>

<p>If I use Javascript's split function combined with regex, I can capture all information on cost by doing:</p>

<pre><code>var hash = window.location.hash;
hash = hash.split(/cost.*&amp;/);
</code></pre>

<p>Right now, this will obviously return an array in two parts the first being <code>/items#rarity=rare,common,uncommon&amp;</code> and <code>category=primary</code> as the split function will split on the condition supplied which in my case matches the string from regex.</p>

<p>Is there any way I can capture the extracted string from the split function so I can then parse the cost string?</p>