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;
"thisStringIsGood"
// insert a space before all caps
.replace(/([A-Z])/g, ' $1')
// uppercase the first character
.replace(/^./, function(str){ return str.toUpperCase(); })
const camelCase = (string) => {
function camelize(str) {
return str
.replace(/(?:^w|[A-Z]|w)/g, function(word, index) {
return index === 0 ? word.toLowerCase() : word.toUpperCase();
})
.replace(/s+/g, "");
}
const newText = camelize(string);
return newText
};
String.prototype.toCamelCase = function () {
let STR = this.toLowerCase()
.trim()
.split(/[ -_]/g)
.map(word => word.replace(word[0], word[0].toString().toUpperCase()))
.join('');
return STR.replace(STR[0], STR[0].toLowerCase());
};
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
}