private static String replaceStars(String init){
  StringBuilder builder=new StringBuilder();
  char[] chars=init.toCharArray();
  for (int i=0; i < chars.length; i++) {
    if (chars[i] == '*' && i == 0 && chars.length > 1 && chars[i + 1] == ' ') {
      builder.append("(?:.+ |)");
      i++;
    }
 else     if (chars[i] == '*' && i < (chars.length - 1) && i > 0 && chars[i + 1] == ' ' && chars[i - 1] == ' ') {
      builder.deleteCharAt(builder.length() - 1);
      builder.append("(?:.+|)");
    }
 else     if (chars[i] == '*' && i == (chars.length - 1) && i > 0 && chars[i - 1] == ' ') {
      builder.deleteCharAt(builder.length() - 1);
      builder.append("(?: .+|)");
    }
 else     if (chars[i] == '*') {
      builder.append("(?:.*)");
    }
 else {
      builder.append(chars[i]);
    }
  }
  return builder.toString();
}

private static String replaceStars ( String init ) { StringBuilder builder = new StringBuilder ( ) ; char [ ] chars = init . toCharArray ( ) ; for ( int i = 0 ; i < chars . length ; i ++ ) { if ( chars [ i ] == '*' && i == 0 && chars . length > 1 && chars [ i + 1 ] == ' ' ) { builder . append ( "(?:.+ |)" ) ; i ++ ; } else if ( chars [ i ] == '*' && i < ( chars . length - 1 ) && i > 0 && chars [ i + 1 ] == ' ' && chars [ i - 1 ] == ' ' ) { builder . deleteCharAt ( builder . length ( ) - 1 ) ; builder . append ( "(?:.+|)" ) ; } else if ( chars [ i ] == '*' && i == ( chars . length - 1 ) && i > 0 && chars [ i - 1 ] == ' ' ) { builder . deleteCharAt ( builder . length ( ) - 1 ) ; builder . append ( "(?: .+|)" ) ; } else if ( chars [ i ] == '*' ) { builder . append ( "(?:.*)" ) ; } else { builder . append ( chars [ i ] ) ; } } return builder . toString ( ) ; }
replaces the * characters in the string by a proper regular expression
