How to replace substrings containing any integer in java?
4 answers
Edit 1: After the question has been changed, one should use
:\d+:
and inside Java
:\\d+:
This is the answer to replacing :: .
This is the regex you should be using:
:\d*:
And here's the running JavaCode running:
String str = "Hello :4: World";
String s = str.replaceAll(":\\d*:","");
System.out.println(s);
One problem with replaceAll is often that the corrected string is returned . The string object from which replaceAll was called does not change.
0
source to share