I need some help on my regex. Given a string such as "1234-abc" or "1234 abc" or "1234abc", I simply want to use a regex that splits the string into two parts. i.e. "1234" and "abc". So the output would be an array like so: array[0] = "1234" and array[1] = "abc".

Here is my current code which works fine for the number part, but does not handle the text part correctly.

I need some help on my regex. Given a string such as "1234-abc" or "1234 abc" or "1234abc", I simply want to use a regex that splits the string into two parts. i.e. "1234" and "abc". So the output would be an array like so: array[0] = "1234" and array[1] = "abc".

Here is my current code which works fine for the number part, but does not handle the text part correctly.

The most efficient way to do it is by using two capture groups within the regular expression.

What you want is to capture numbers at the start (\d+)and for there to be an optional space or a dash [ \-]?and to then capture some word characters (\w+)

Which ends up being:

var match = input.match((/\\d+)[ \\-]?(\\w+)/),
// match[0] is the complete string that fits with the regular expression
// match[1] is the first capture group, from (\\d+)
number = match[1],
// match[2] is the second capture group, from (\\w+)
text = match[2];