JQuery/JavaScript: how to split string based on Caps letter

In certain cases, you might got a need to change a string content in order to display it in more human readable format. recently I faced a need where I need to tokenize a string based on caps letter and add spaces between words

Using the built-in RegEx feature on Javascript, you can split the string and tokenize it based on the capital letters on the string. For example if you would like to split the string “TestStringValue” to be “Test String Value” you can simply use the following syntax:

/*split string based on Cap letter, then joins the resulted array elements with space between each array entry*/
split(/(?=[A-Z])/).join(" ") 

to try it, use the following code:

alert(  window.prompt("Tokenize String: ", "TestStringValue").split(/(?=[A-Z])/).join(" ")  )