var text = 'helloThereMister';
var result = text.replace( /([A-Z])/g, " $1" );
var finalResult = result.charAt(0).toUpperCase() + result.slice(1);
console.log(finalResult);
str.toUpperCase() === str || str.toLowerCase() === str;
function sameCase(str) {
return /^[A-Z]+$/.test(str) || /^[a-z]+$/.test(str);
}
var haystack = "A. BAIL. Of. Hay.";
var needle = "bail.";
var needleRegExp = new RegExp(needle.replace(/[-[]{}()*+?.,^$|#s]/g, "$&"), "i");
var result = needleRegExp.test(haystack);
if (result) {
// Your code here
}