I have:
0001-2015
How I can split this string to 0001 and 2015?
I have:
0001-2015
How I can split this string to 0001 and 2015?
Use split
instead of regex
. It will be much faster than regex
var str = '0001-2015';
var arr = str.split('-'); // ["0001", "2015"]
If you really want to use regular expressions - you can use /(\d+)/g
regex , this means "capturing group having one or more digits". It will exactly extract both digital parts from your string.
But in current specification of your task using split
looks pretty enough.