Get the environment variable's value
private String replaceWithEnvironmentVariables(String specialChars) {


Naming. specialChars are no special chars, it's String in which variables get substituted. Maybe pattern or alike.

String result="";


Spacing. Needless assignment as it gets overwritten 3 lines below. Should be

String result = specialChars;

boolean flag=true;


Naming... flag means actually nothing.

String temp = "";


And neither does temp. A single meaningless name is sometimes tolerable (especially in short methods), but with more, it's getting harder and harder to understand.

char dollarCheck = '$';


Dollar cheque? Check? ✔? It should be a constant and called e.g.

private static static DOLLAR_CHAR = '$';


or better "variable start char" or alike. Prefer to express what it means to what it is, as the latter is obvious.

    if (index == -1){
        result = result.replaceAll("[{},$]", "");
        return result;
    }


I'd personally throw an exception for malformed inputs like foo}bar.

if(slashCheck==result.charAt(i))


That's Yoda style, the form var == expr is more common.

Now I've got lost... you parse the string somehow... OK, let's ignore it.

String sub = temp.replaceAll("[{},$/]", "");
if(sub==null || sub.length()==0){


Know your libraries. sub can't be null. Instead of sub.length()==0, you can use sub.isEmpty().

sub="";


This line is useless now.

... catch ...


Just leave it out. Let the user deal with the problem. You may know, that e.g., using an empty String is acceptable in case of an error, but you surely don't know it here. Just document the exception and let the poor user deal with it. Here, "user" means you in another piece of the program.

NullPointerException


I see a single place where it can be thrown:

String returnSub = getEnvironmentVariableValue(sub);
result = result.replace(temp, returnSub);


Don't let this happen. Maybe throw a new MissingEnvironmentVariableException(sub), maybe allow the caller to specify a replacement, e.g., like this

private String replaceWithEnvironmentVariables(
        String pattern, 
        Map&lt;String, String&gt; specificReplacements,
        String defaultReplacement) {...}


where specificReplacements contains the default values for missing variables and defaultReplacement gets used as a last resort. Allow defaultReplacement to be null, but then throw an exception if it should be needed.