The following Java snippet removes all
non-digit characters from a String.
Non-digit characters are any characters that are not in the following set
[0, 1, 2, 3, 4 ,5 ,6 ,7 ,8, 9].
For a summary of regular-expression constructs and information on the character classes supported by Java pattern visit the following link.
\\D pattern that we used in our code is a predefined character class for non-digit characters. It is equivalent to
[^0-9]that negates the predefined character class for digit characters