1Pattern p = Pattern.compile("(\\d)(.*)(\\d)");
2String input = "6 example input 4";
3Matcher m = p.matcher(input);
4if (m.find()) {
5 // replace first number with "number" and second number with the first
6 String output = m.replaceFirst("number $3$1"); // number 46
7}