I need to convert an alphanumeric string, which is written in camelCase to regular string. My input can be any of the following strings:
var strs = {
input: [
"thisStringIsGood",
"somethingLikeThis",
"a123CapsHere345AndHEREButNOT678Here90End",
"123CapsHere345AndHEREButNOT678Here90e",
"ABCAcryonym",
"xmlHTTPRequest",
"thisDeviceHasA3PrintingService"
],
expectedResult: [
"This String Is Good",
"Something Like This",
"A123 Caps Here345 And HERE But NOT678 Here90 End",
"123 Caps Here345 And HERE But NOT678 Here90 e",
"ABC Acryoynm",
"Xml HTTP Request",
"This Device Has A3 Printing Service"
]
};
After for converting the string into the expected format I'm doing this:
function capSplit(str) {
return str.replace(/(^[a-z]+)|[0-9]+|[A-Z][a-z]+|[A-Z]+(?=[A-Z][a-z]|[0-9])/g, function (match, first) {
if (first) match = match[0].toUpperCase() + match.substr(1);
return match + ' ';
})
}
But the problem is that the spaces are added with the numbers as well. I need to convert string "thisDeviceHasA3Service"
to be converted as "This Device Has A3 Printing Service"
but the function capSplit(str)
gives me This Device Has A 3 Printing Service
I don't know what I'm missing. Here is the fiddle