I have a javascript value holding a string:
value = "123 / 15 - Value1"
And I'm trying to split on delimiters so that I can have each number and the string value is their own variables.
I tried this:
value = "123 / 15 - Value1"
splitVal = value.split(/[" ".,\/ -]/);
number1 = splitVal[0];
number2 = splitVal[1];
name = splitVal[2];
But when I console log number1,number2 and name I only get '123' in the console, the other 2 are blank.
What am I doing wrong here as far as splitting a string by both a hyphen and a slash, as well as spaces?
valuein a generic way.[" "]I think you either want"or ` ` (space) here. This regex will match either of the two and uselessly repeats".[ /]the sequence between the two numbers123 / 15matches three times, hence why you get empty results. If you put a quantifier after the square brackers...]+you would only get three items after splitting.