Alachisoft.NCache.Common.MessageUtil Maven / Gradle / Ivy
package Alachisoft.NCache.Common;
public class MessageUtil {
private static final char ESCAPES[] = {'$', '^', '[', ']', '(', ')', '{', '|', '+', '\\', '.', '<', '>'};
public static String wildcardToRegex(String pattern) {
String result = "^";
for (int i = 0; i < pattern.length(); i++) {
char ch = pattern.charAt(i);
boolean escaped = false;
for (int j = 0; j < ESCAPES.length; j++) {
if (ch == ESCAPES[j]) {
result += "\\" + ch;
escaped = true;
break;
}
}
if (!escaped) {
if (ch == '*') {
result += ".*";
} else if (ch == '?') {
result += ".";
} else {
result += ch;
}
}
}
result += "$";
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy