Reputation: 1489
I want to match all upper case letter and lower case letter using regular expression, in my code I'm matching only particular character, but I want to match all character irrespective of capital or small. Here is my code
$scope.set_color = function(row) {
var inputString = row.Subject;
for (i = 0; i < inputString.length; i++) {
//var findme = "HOT RUSH";
//var str = findme.match(/\b([a-z][A-Z])\b/);
var findmeCap = "HOT RUSH";
var findmeSmall = "hot rush";
if (inputString.indexOf(findmeCap) > -1 || inputString.indexOf(findmeSmall) > -1) {
return {
'background-color': '#FFCCCB'
}
}
}
}
How I can do this?
Upvotes: 0
Views: 1488
Reputation: 1489
Below code worked, in my case.
$scope.set_color = function (row) {
var inputString = row.Subject;
for (i = 0; i < inputString.length; i++) {
var findMe = "hot rush";
if (inputString.toLowerCase().indexOf(findMe) > -1) {
return { 'background-color': '#FFCCCB' }
}
}
}
Upvotes: 0
Reputation: 930
You can do string.toUpperCase and string.toLowerCaseAnd then compare the result. And change color accordingly result.
var a = "hello";
var b = "HELLO";
if (a.toUpperCase() === b.toUpperCase()) {
alert("string is equal");
//change color
}
Another solution is https://github.com/nickuraltsev/ignore-case
This works like that only so you can use any of these.
Upvotes: 2
Reputation: 182
var inputString = row.Subject;
var findMe = "hot rush";
if(inputString.toLowerCase().indexOf(findMe) !== -1) {
return {'background-color': '#FFCCCB'};
}
This is how I would handle the problem.Regex is not what you need here. And get rid of the for loop.
Upvotes: 1