I have a string which I want to split into chunks using the .split() function.
Example strings
59 Samuël 1 en 2 // Example 1
1 Saul omgekomen door het zwaard // Example 2
622 Koningen 1 tot 10 // Example 3
Expected output
['59', 'Samuël 1 en 2'] // Output example 1
['1', 'Saul omgekomen door het zwaard'] // Output example 2
['622', 'Koningen 1 tot 10'] // Output example 3
I tried the following code, based on anwsers found in other topics.
var example_1 = '59 Samuël 1 en 2';
var example_2 = '1 Saul omgekomen door het zwaard';
var example_3 = '622 Koningen 1 tot 10';
console.log(example_1.split(/(\d+)/));
console.log(example_2.split(/(\d+)/));
console.log(example_3.split(/(\d+)/));
But the output is not the expected output, eg. ['59', 'Samuël 1 en 2']
Can someone point me into the right direction?
['59', 'Samuël 1 en 2']"59 Samuël 1 en 2".match(/(\d\d) (.*)/).slice(1)This basically creates 2 capture groups, that I then slice of the first return as that's the original string, the rest are the capture groups your interested in.