I have a string. How I can check if the string is a regular expression or contains regular expression or it is a normal string?
I have a string. How I can check if the string is a regular expression or contains regular expression or it is a normal string?
If anyone just want to distinguish just plain text strings and regular-expressions:
static boolean hasSpecialRegexCharacters(String s){
Pattern regexSpecialCharacters = Pattern
.compile("[\\\\\\.\\[\\]\\{\\}\\(\\)\\<\\>\\*\\+\\-\\=\\!\\?
\\^\\$\\|]");
return regexSpecialCharacters.matcher(s).find();
}