I have a string that I want to make sure that the format is always a +
followed by digits.
The following would work:
String parsed = input
You can use this expression:
String r = s.replaceAll("((?
The idea is to replace any non-digit when it is not the initial character of the string (that's the (? part with a lookbehind) or any character that is not a digit or plus that is the initial character of the string (the
^[^0-9+]
part).
Demo.