java string replace all non digits

Ads
 

java string replace all non digits

Hi,

I am doing some processing on the text data. I have requirement to remove all the charaters from the data except the digits.

How to replace all non digits in a string with some character in Java?

Thanks

View Answers

February 20, 2020 at 12:31 AM

Hi,

Regular expression can be used for replacing in combination with the replaceAll function of String.

Following regular expression can be used:

"[^\\d]"

Here is complete program:

public class ReplaceNonDigit {

    public static void main(String[] args) {
        String data = "Hello you can contact me at my number 999999999. I am in Delhi India.";
        data = data.replaceAll("[^\\d]", "");
        System.out.println(data);

    }

}

Thanks

Ads









Related Tutorials/Questions & Answers:
java string replace all non digits
java string replace all non digits  Hi, I am doing some processing on the text data. I have requirement to remove all the charaters from the data except the digits. How to replace all non digits in a string with some character
Java replace all non alphanumeric
Java replace all non alphanumeric  Hi, In Java how to replace all non alphanumeric characters with blank? Share me the best code for java replace...]" for finding all non alphanumeric characters and then replace it with required
Advertisements
MySQL replace all non alphanumeric characters
MySQL replace all non alphanumeric characters  Hi, How to replace all non alphanumeric characters in MySQL? Thanks
Java String : Replace All
Java String : Replace All This section defines how to replace all character... : You can replace all specific character in a given string with another character... method to replace all spaces by calling one of String method replaceAll("
How to replace all occurrences of a string in JavaScript?
in JavaScript. There are many ways to replace all occurrences of a string in JavaScript... of replacing string in JavaScript. 1. Replace all occurrences with regular expression... the spitted data with the replacement. So, this way replace all string is achieved
How to replace all occurrences of a string in JavaScript?
in JavaScript. There are many ways to replace all occurrences of a string in JavaScript... of replacing string in JavaScript. 1. Replace all occurrences with regular expression... the spitted data with the replacement. So, this way replace all string is achieved
How to replace all occurrences of a string in JavaScript?
in JavaScript. There are many ways to replace all occurrences of a string in JavaScript... of replacing string in JavaScript. 1. Replace all occurrences with regular expression... the spitted data with the replacement. So, this way replace all string is achieved
MySql find and replace string
MySql find and replace string  How to find and replace string or special characters in MySql & PHP?   Find and Replace String PHP $result = preg_replace('/\band\b/i', 'foo', $subject
String doubt replace function
String doubt replace function  What is the output and why of below : String s1 = "Hello"; if(s1.replace('H','H')== "Hello") System.out.println("yes"); else System.out.println("No"); if(s1.replace("H", "H")== "Hello
Replace String in PHP - PHP
Replace String in PHP  What is the fastest way of replacing string in PHP Code?  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorial/php/phpbasics/PHP-Array-Replace.html Thanks
java program_big digits multiplication..
java program_big digits multiplication..  i want program about big digits multiplication program using java..plz tel me answer
String replaceAll in java
String replaceAll in java In this section you will learn about replaceAll() method  in java, This will replace each of the sub string ... would replace the original string. public class ReplaceAll { public
find and replace in java
find and replace in java  Need 'find and replace' function in Java to find special keyword in XMl such as @,#,!,%..and replace with their corresponding entities
find all unique character in string using java
find all unique character in string using java  example: hello how are you. output should be waryu
java replace dot with comma
java replace dot with comma  Hi, How to replace dot with command in Java program? thanks   Hi, Here is simple example for replacing... { public static void main(String[] args) { String str="Hello. How are you
java replace dot with comma
java replace dot with comma  Hi, How to replace dot with command in Java program? thanks   Hi, Here is simple example for replacing... { public static void main(String[] args) { String str="Hello. How are you
Non-virtual Methods in Java - java tutorials
The better way to achieve the non-virtual function in java is that make all...: #000000; } Non Virtual Methods in Java Lets see the concept of virtual... hierarchy. In Java programming language all the methods are virtual, i.e.
Write a function that reads a string of digits, possibly preceded by + or -, and converts this string to the integer value it represents.
Write a function that reads a string of digits, possibly preceded by + or -, and converts this string to the integer value it represents.  Write a function that reads a string of digits, possibly preceded by + or -, and converts
MySQL Replace
; MySQL Replace function finds and replaces the occurrences of specified string...: REPLACE( String_Text, String_FROM, String_TO); where String_Text...;In the query given below,  "Roseindia.net" is the original string and all
Learning Java for non programmers
Learning Java for non programmers - Learn Java from scratch If you are non... on all platforms. Java is wide choice of programming language for developing... of Java for non programmers to learn Java language from scratch
string
string  a java program to replace all matching substrings
Replace
Replace   Hi, I have two text files in two diff locatons.The text file like below using java program 1)a.txt 1 abc bangalore 2 def adfsdf 3 ghij asdfdsad 2)b.txt A B C Now i want output is like below
JavaScript replaceAll function to replacing all occurrences of a string
with replacement. You can find many examples at How to replace all occurrences of a string... occurrences of a string. How make JavaScript replaceAll function to replacing all... web applications. There are 2-3 ways you can replace all the occurrences
JavaScript replaceAll function to replacing all occurrences of a string
with replacement. You can find many examples at How to replace all occurrences of a string... occurrences of a string. How make JavaScript replaceAll function to replacing all... web applications. There are 2-3 ways you can replace all the occurrences
JavaScript replaceAll function to replacing all occurrences of a string
with replacement. You can find many examples at How to replace all occurrences of a string... occurrences of a string. How make JavaScript replaceAll function to replacing all... web applications. There are 2-3 ways you can replace all the occurrences
Java String
Java String  You are given two strings S1 and S2,Delete from S2 all those characters which occur in s1 also and create a clean S2 with the relevant characters deleted..write a pgm for this..pls send as soon as possible Thank you
Java String
Java String       In this section, you will learn about the java string. Java String is a set.... All String literals are instances of this class and two string literals
C Replace String
C Replace String       In this section, you will learn how to replace a string in C.  Here a function pointer replace is created in which variables st, orig, repl
Java String - Java Beginners
Java String  How to seperate the string into characters.  there is a method called getChars() in String class,plz use that and separate into characters so plz verify the String api for related questions 
How To Append String In Java
How To Append String In Java In this section we will read about how to append String in Java. Here we will see the solution of this question through a simple example. There are various ways to append String in Java. Below, we
String in Java - Java Beginners
]); } } } ---------------------------------------------------- I am sending simple code of String array. If you are beginner in java...String in Java  hiiiii i initialise a String array,str[] with a size... in advance   Hello Antony Insted Using String Array Use StringBuffer

Ads