First, I'll note that the code you've quoted has a syntax error:
str = "active - error - oakp-ms-001 Volume Usage-E:\ PercentUsed E:\"
There's no ending "
on that string, becaue the \"
at the end is an escaped "
, not a backslash followed by an ending quote.
If there were an ending quote on the string, it would have no backslashes in it (the \
with the space after it is an invalid escape that ends up just being a space).
So let's assume something valid rather than a syntax error:
str = "active - error - oakp-ms-001 Volume Usage-E:\\ PercentUsed E:\\";
That has backslashes in it.
What you need to do doesn't really involve "splitting" at all but if you want to split on something containing a backslash:
var parts = str.split("\\"); // Splits on a single backslash
But I'm not seeing how splitting helps with what you've said you want.
You have to identify what parts of the string near what you want are consistent, and then create something (probably a regular expression with a capture group) that can find the text that varies relative to the text that doesn't.
For instance:
var str = "active - error - oakp-ms-001 Volume Usage-E:\\ PercentUsed E:\\";
var match = str.match(/error - (.*?) ?Volume/);
if (match) {
console.log(match[1]); // oakp-ms-001
}
There I've assumed the "error - "
part and the "Volume"
part (possibly with a space in front of it) are consistent, and that you want the text between them.
Live Example