private String subEdit(String retval, String pattern, String value,
			Pattern p) {
		int pos = retval.indexOf(pattern) + pattern.length();
		if (retval.charAt(pos) == '}') {
			return retval.replace(pattern + "}", valueOf( value ));

		}
		if (retval.charAt(pos) == ':') {
			int endpos = retval.indexOf('}', pos);
			String idxStr = retval.substring(pos + 1, endpos);
			int patternIdx = Integer.valueOf(idxStr);
			try {
				Matcher m = p.matcher( valueOf( value ));
				m.find();
				if (m.groupCount() < patternIdx)
				{
					throw new IllegalArgumentException( String.format("Subpattern %s does not exist in %s matching %s", patternIdx, p, valueOf( value )) );
				}
				return retval.replace(
						retval.substring(retval.indexOf(pattern), endpos + 1),
						m.group(patternIdx));
			} catch (Exception e) {
				e.printStackTrace();
				throw new IllegalArgumentException(e.getMessage(), e);
			}
		}
		throw new IllegalArgumentException(String.format(
				"Bad pattern string: %s", pattern));
	}