public static boolean isPossibleRegex(String str){
  for (int i=0; i < str.length(); i++) {
switch (str.charAt(i)) {
case '*':
      return true;
case '{':
    if (i < str.length() - 1 && str.charAt(i + 1) != '}')     return true;
  break;
case '|':
return true;
case '?':
if (i > 1 && str.charAt(i - 1) == ')') return true;
break;
default :
break;
}
}
return false;
}

public static boolean isPossibleRegex ( String str ) { for ( int i = 0 ; i < str . length ( ) ; i ++ ) { switch ( str . charAt ( i ) ) { case '*' : return true ; case '{' : if ( i < str . length ( ) - 1 && str . charAt ( i + 1 ) != '}' ) return true ; break ; case '|' : return true ; case '?' : if ( i > 1 && str . charAt ( i - 1 ) == ')' ) return true ; break ; default : break ; } } return false ; }
checks whether the string could possibly represent a regular expression ( this is just a first , fast guess , which will need to be verified by actually constructing the regex using the constructregex method below ) .
