So for example:
Foo : Bar
Could also be looked up as FOO, foo, fOO etc?
So for example:
Foo : Bar
Could also be looked up as FOO, foo, fOO etc?
No. You should lowercase/uppercase all your keys if you want that.
redis keys is case sensitive,my solution is that: key-->Foo:Bar keyword-->f
keys("[fF]*") or keyword-->foo
keys("[fF][oO][oO]*") you have to convert normal string to this format '[Ff][Oo]';
i write a method for this:
public static String toIgnoreCasePattern(String str){
StringBuilder sb = new StringBuilder();
char []chars = str.toCharArray();
char upperCaseC;
for(char c : chars){
boolean isLowerCase = Character.isLowerCase(c);
upperCaseC = isLowerCase ? Character.toUpperCase(c) : c;
sb.append("[").append(c).append(upperCaseC).append("]");
}
return sb.toString();
}
I hope this answer can help you.
In C#
public static String toIgnoreCasePattern(String str)
{
StringBuilder sb = new StringBuilder();
char[] chars = str.ToCharArray();
char upperCaseC;
foreach (var c in chars)
{
bool isLowerCase = char.IsLower(c);
upperCaseC = isLowerCase ? char.ToUpper(c) : c;
sb.Append("[").Append(c).Append(upperCaseC).Append("]");
}
return sb.ToString();
}
in Python (to continue the examples)
def nocase(s):
key = ''
for c in s:
if c.isalpha():
key += f"[{c.upper()}{c.lower()}]"
else:
key += c
return key
# equivalent to
nocase = lambda s: ''.join([f"[{c.upper()}{c.lower()}]" if c.isalpha() else c for c in s])
This will work with intermixed wildcards.
>>> print(nocase('test'))
[Tt][Ee][Ss][Tt]
>>> print(nocase('*Tester1*'))
*[Tt][Ee][Ss][Tt][Ee][Rr]1*
Kudos to the original idea
© 2022 - 2024 — McMap. All rights reserved.