Nicholas Murray Nicholas Murray - 1 year ago 174
Javascript Question

Javascript Split string on UpperCase Characters

How do you split a string into an array in Javascript by UpperCase character?

So I wish to split:



('This', 'Is', 'The', 'String', 'To', 'Split')

Answer Source

I would do this with .match() like this:


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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download