I have searched online but it really doesnt make much sense.
I am trying to split a string and keep the delimiters too.
For example, I have this string:
var str = '45612+54721/121*124.2';
And, I would like to split it based on the operations & keep the operations.
So the output must look like this
[45612], [+], [54721], [/], [121], [*], [124.2];
If you use strings’ split with a regex, any captured groups become part of the resulting array.
var str = '45612+54721/121*124.2';
var tokens = str.split(/([+/*])/);
console.log(tokens);