So if I wished to replace all numbers with a given value, I could just use
"hello8".replaceAll("[1-9]", "!");
hello!
Now is there a way to get the number that is actually being matched and add that to the string?
e.g.
hello!8
One option is to set a capturing group:
"hello8".replaceAll("([1-9])", "!$1");
Another option is to use $0, which means the whole match:
"hello8".replaceAll("[1-9]", "!$0");
See also: regular-expressions.info/java