I need to identify a String if the character on it includes only numbers, with alphabet (a custom string, name, code, or whatever) or its a GAE Key.
Here is my code:
    try {
        Class clazz = Class.forName(typeName);
        Object one = null;
        if(key.matches("[0-9]+")){ // Long
            one = store.get(clazz, Long.valueOf(key));
        } else if(key.matches("^[0-9A-Za-z._-]{1,500}$")) { // GAE datastore key
            one = store.get(clazz, KeyFactory.stringToKey(key));
        } else {
            one = store.get(clazz, String.valueOf(key));
        }
        jsonString =new Gson().toJson(one);
    } catch (Exception e){
        setStatus(Status.SERVER_ERROR_INTERNAL);
        e.printStackTrace();
    }
The problem here is that the second statement in the if-else catches even String "aaa" I need to have some way of differentiating a GAE datastore key from a regular strings that is not really a GAE key format.
 
     
    