Limited splits without losing the rest of the string?
<p>Say I have:</p>

<p><code>var str = "this is a string separated by spaces";</code></p>

<p>and I did:</p>

<p><code>alert(str.split(" " , 1));</code></p>

<p>the outcome would be <code>"this"</code></p>

<p>Whereas I want the outcome to be <code>"this,is a string separated by spaces"</code></p>

<p>maybe split isn't the right method? </p>

<p>What I'm trying to do is separate a string into parts based on semicolons, unless those semicolons are in quotes. For example, I would want </p>

<p><code>randomnessstuff;morestuff;some more stuff</code></p>

<p>to be in three parts, so I've been doing:</p>

<pre><code>var str = "randomnessstuff;morestuff;some more stuff";
var parts = str.split(";");
</code></pre>

<p>Which has been working fine, but if the semicolon is in quotes, I want it to NOT be separated into another part. </p>

<p>for example, with:</p>

<p><code>var str = "randomnessstuff;morestuff and a semicolon in quotes : ";";some more stuff";</code></p>

<p>I would want part 1 to be <code>randomnessstuff</code> , part 2 to be <code>morestuff and a semicolon in quotes : ";"</code> , and part 3 to be <code>some more stuff</code></p>

<p>of course, if I just did split with the semicolon again, it would make part 3 the quote.</p>

<p>What I'm hoping to do is have a loop that checks the semicolons one by one to see if they're in quotes, and if not, to split with them. If this last bit didn't make any sense, then please just answer the first question, about using split without losing the rest of the string.</p>
