private static String replaceOptionalVariable(String s,Movie movie,boolean forFilename){
  Pattern regex=Pattern.compile("\\$.{1}");
  Matcher mat=regex.matcher(s);
  if (mat.find()) {
    String rep=createDestination(mat.group(),movie,forFilename);
    if (rep.isEmpty()) {
      return "";
    }
 else {
      return s.replace(mat.group(),rep);
    }
  }
 else {
    return "";
  }
}

private static String replaceOptionalVariable ( String s , Movie movie , boolean forFilename ) { Pattern regex = Pattern . compile ( "\\$.{1}" ) ; Matcher mat = regex . matcher ( s ) ; if ( mat . find ( ) ) { String rep = createDestination ( mat . group ( ) , movie , forFilename ) ; if ( rep . isEmpty ( ) ) { return "" ; } else { return s . replace ( mat . group ( ) , rep ) ; } } else { return "" ; } }
replaces an optional variable , eg " { year $ y } " < br > if we have a year , " year 2013 " will be returned < br > if $ y replacement was empty , the complete optional tag will be empty .
