You can use regex like (value\s)([\w\.?]+) to match and group it,then use $1 and $2 to replace it.
In your case,$1 represent for vaule\s and $2 represent [\w\.]+,we just need to reserve $1 and replace $2
String str1 = "Foo value 1.1.1".replaceAll("(value\\s)([\\w\\.?]+)", "$1AAA");
String str2 = "Foo value 1.1".replaceAll("(value\\s)([\\w\\.?]+)", "$1BBB");
String str3 = "Foo value Stackoverflow".replaceAll("(value\\s)([\\w\\.?]+)", "$1CCC");
System.out.println(str1);//output: Foo value AAA
System.out.println(str2);//output: Foo value BBB
System.out.println(str3);//output: Foo value CCC
Update,an more elegant way is to change regex to (?<=value\s)[\w\.?]+,output will be the same
String str1 = "Foo value 1.1.1".replaceAll("(?<=value\\s)[\\w\\.?]+", "AAA");
String str2 = "Foo value 1.1".replaceAll("(?<=value\\s)[\\w\\.?]+", "BBB");
String str3 = "Foo value Stackoverflow".replaceAll("(?<=value\\s)[\\w\\.?]+", "CCC");
System.out.println(str1);//output: Foo value AAA
System.out.println(str2);//output: Foo value BBB
System.out.println(str3);//output: Foo value CCC