I have a next string:
$scope.string = "User {{User Firstname}} </p><p>System {{Reported System Name}} </p><p>Desc {{Description}}</p><ol></ol>"
I'm trying to achieve next result:
$scope.string = "User {{userFirstname}} </p><p>System {{reportedSystemName}} </p><p>Desc {{description}}</p><ol></ol>"
With help of regex I can find necessary for camelize text
if ($scope.string.match(/\{\{(.*?)\}\}/g)){
for (var i = 0; i < $scope.string.match(/\{\{(.*?)\}\}/g).length; i ++){
$scope.string.match(/\{\{(.*?)\}\}/g)[i] = camelizeBrackets($scope.string.match(/\{\{(.*?)\}\}/g)[i])
}
}
But the function camelizeBrackets
which I have found here and modified to work with text inside curly braces doesn't work at all
function camelizeBrackets(str) {
return str.replace(/\{\{(?:^\w|[A-Z]|\b\w|\s+)\}\}/g, function(match, index) {
if (+match === 0) return "";
return index === 0 ? match.toLowerCase() : match.toUpperCase();
});
}
Could anybody explain me what I'm doing wrong?