I am parsing some text with JavaScript. Let's say I have some string:
"hello wold <1> this is some random text <3> foo <12>"
I need to place the following sub strings in an array:
myArray[0] = "hello world ";
myArray[1] = "<1>";
myArray[2] = " this is some random text ";
myArray[3] = "<3>";
myArray[4] = " foo ";
myArray[5] = "<12>";
Note that I am spliting the string whenever I encounter a <"number"> sequence
I have tried spliting the string with a regular expresion /<\d{1,3}>/
but when I do so I loose the <"number"> sequence. In other words I end up with "hellow world", " this is some random text ", " foo ". Note that I loose the strings "<1>", "<3>" and "<12>" I will like to keep that. How will I be able to solve this?
You need to capture the sequence to retain it.
In case there are issues with the capturing group in some browsers, you could do it manually like this: