I have a string in the following format:
90000 - 90000
Where the numbers can be of a variable length, and then there is a space, hyphen, space between them. I\'m tr
You can use split
function:
var s = '90000 - 90000';
var a = s.split(/[ -]+/);
console.log(a);
Output:
["90000", "90000"]
There are multiple problems with your Regex statement.
First, if it is a regular expression it does not need to be enclosed in quotes. Second, you forgot the terminating /
character.
Third, and most importantly, regular expressions are not needed here:
var string = "90000 - 90000";
var array = string.split(" - ");
console.log(array);
outputs:
["90000", "90000"]