I would do this with .match()
like this:
'ThisIsTheStringToSplit'.match(/[A-Z][a-z]+/g);
it will make an array like this:
['This', 'Is', 'The', 'String', 'To', 'Split']
edit: since the string.split()
method also supports regex it can be achieved like this
'ThisIsTheStringToSplit'.split(/(?=[A-Z])/); // positive lookahead to keep the capital letters
that will also solve the problem from the comment:
"thisIsATrickyOne".split(/(?=[A-Z])/);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…