class UserSearchUtils {

	static String escapeSomeRegexCharacters(String input, char[] doNotEscape) {
		StringBuffer buffy = new StringBuffer();
		for (int i = 0; i < input.length(); i++) {
			char c = input.charAt(i);

			if (contains(doNotEscape, c)) {
				// a bit inefficient, but the array should always be short
				buffy.append(c);
				continue;
			}

			switch (c) {
				case '^':
					buffy.append("\\^");
					break;
				case '.':
					buffy.append("\\.");
					break;
				case '$':
					buffy.append("\\$");
					break;
				case '(':
					buffy.append("\\(");
					break;
				case ')':
					buffy.append("\\)");
					break;
				case '[':
					buffy.append("\\[");
					break;
				case ']':
					buffy.append("\\]");
					break;
				case '+':
					buffy.append("\\+");
					break;
				case '&':
					buffy.append("\\&");
					break;
				case '{':
					buffy.append("\\{");
					break;
				case '}':
					buffy.append("\\}");
					break;
				case '*':
					buffy.append("\\*");
					break;
				case '?':
					buffy.append("\\?");
					break;
				case '|':
					buffy.append("\\|");
					break;
				default:
					buffy.append(c);
					break;
			}
		}
		return buffy.toString();
	}

}