static String convertPattern(String pattern){
  if (!pattern.contains("{")) {
    return pattern;
  }
 else {
    return pattern.replaceAll("(\\A|\\G|[^\\\\]|\\\\\\\\)[{]([0-9]+)[}]","$1\\\\$2");
  }
}

static String convertPattern ( String pattern ) { if ( ! pattern . contains ( "{" ) ) { return pattern ; } else { return pattern . replaceAll ( "(\\A|\\G|[^\\\\]|\\\\\\\\)[{]([0-9]+)[}]" , "$1\\\\$2" ) ; } }
convert a pattern from the input format , with { n } for captured groups , to the \ n format used by java regexps .
