I have a simple method that searches for and compiles the pattern for the given string
String search = I GIVE IT SOME STRING;
String trimmedSearch = search.trim();
if (trimmedSearch.isEmpty())
{
pattern_ = null;
}
else if (trimmedSearch.contains("*") || trimmedSearch.contains("(")
|| trimmedSearch.contains(")") || trimmedSearch.contains("?")
|| trimmedSearch.contains(".") || trimmedSearch.contains("[")
|| trimmedSearch.contains("]") || trimmedSearch.contains("{")
|| trimmedSearch.contains("}") || trimmedSearch.contains("^")
|| trimmedSearch.contains("|") || trimmedSearch.contains("$")
|| trimmedSearch.contains("+") || trimmedSearch.contains("\\"))
{
pattern_ = null;
}
else
{
pattern_ = Pattern.compile(trimmedSearch.toUpperCase(), Pattern.CASE_INSENSITIVE);
}
Pattern crashes miserably whenever search is *
Because of that I have the horrible huge if statement checking to make sure that the string does not contain any of the characters that can crash it. But what if I would like to also include them in the search. Is there any way?
Any help will be appreciated, it is very difficult to search for this kind of question or problem anywhere online, and I am starting to lose my mind.