int pos1 = pos + 1; while (pos1 < input.length() && Character.isDigit(input.charAt(pos1))) { int val1 = val*10 + Character.digit(input.charAt(pos1),10); if (val1 >= start.length) break; pos1++; val = val1; } pos = pos1 - 1;
    public String substituteInto(String input) {	// a la Perl, $0 is whole thing, $1 - $9 are subexpressions	StringBuffer output = new StringBuffer();	int pos;	for (pos = 0; pos < input.length()-1; pos++) {	    if ((input.charAt(pos) == '$') && (Character.isDigit(input.charAt(pos+1)))) {		int val = Character.digit(input.charAt(++pos),10);		if (val < start.length) {		    output.append(toString(val));		} 	    } else output.append(input.charAt(pos));	}	if (pos < input.length()) output.append(input.charAt(pos));	return output.toString();    }