Splitting a string using a JavaScript regex but keeping the delimiter?

Viewed 2292

I'm receiving input like:

F12T213B1239T2F13T341F324

and I have to group it by letter followed by the numbers that follows it. So the ideal output would be:

F12,T213,B1239,T2,F13,T341,F324

And then do some processing on the numbers based on the letter that they're with. The letters are fixed, they are always B,F,T

So far, I've tried to split it by letter with:

var separators = ['T', 'B', 'F'];
var parts = input.split(new RegExp('('+separators.join('|')+')'),'g');

But the problem with this is that I end up with just the numbers, I need the letters with them.

Does anyone know how to split a string by certain characters but still keep the characters in the output?

4 Answers
Related