devxlogo

Finding All Digits in a Given String

This regex will help you retrieve all the digits that are present in the string.

Regex is powerful and makes this a simple procedure.

public class FindAllDigitsInString{   public static void main(String args[])   {      FindAllDigitsInString findAllDigitsInString = new FindAllDigitsInString();      findAllDigitsInString.proceed();   }   private void proceed()   {      String alphaNumericString = "No#10,Prime Conclave,56014";      String allDigitsInString= alphaNumericString.replaceAll("[^0-9]", "");               System.out.println("All the digits in string: " + allDigitsInString);   }   }/*

Expected output:

[root@mypc]# java FindAllDigitsInString All the digits in String: 1056014*/

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.