Remove non numeric character in a StringTag(s): String/Number

Using a regular expression to filter all the non-numeric characters and replace them with an empty string.
public class StringUtils {
   public static void main(String[] args) {
      System.out.println(StringUtils.numericOnly("  12B@-3456 , 7890"));
      // output : 1234567890

   public static String numericOnly(String value) {
      return value.replaceAll("[^0-9]", "");

blog comments powered by Disqus