How to check if the string is a regular expression or not

Viewed 28045

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?

6 Answers

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();
}
Related