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 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









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
show how to replace all non alphanumeric characters present in a Java String...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
Advertisements
MySQL replace all non alphanumeric characters
MySQL replace all non alphanumeric characters  Hi, How to replace all non alphanumeric characters in MySQL? Thanks (adsbygoogle = window.adsbygoogle || []).push
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... in-sensitive replace all string in JavaScript: var str2 = "I love dog. Dog found
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
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
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
java program_big digits multiplication..
java program_big digits multiplication..  i want program about big digits multiplication program using java..plz tel me answer
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
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
Replace a String with another using "fn:replace" tag of JSTL
Replace a String with another using <fn:replace> tag of JSTL In this Section, we will replace a String with another string using <fn:replace> tag...;green"> <c:out value="${fn:replace(string,find
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
String replaceAll() Method
that word. This method will replace all the words in a string as shown in the output...;  In this program you will learn how to replace all the words in a String. We are going to use replaceAll() method of String class in Java
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. (adsbygoogle = window.adsbygoogle
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
MySQL Replace
; MySQL Replace function finds and replaces the occurrences of specified string...   Syntax: REPLACE( String_Text, String_FROM, String...;Roseindia.net" is the original string and all occurrences of "i"
Replace Character in String
C:\replace>java Replace Your String before repalce rajesh raju raja... in a given string. To replace a character with the given character in sting first... Replace Character in String      
how to find a dynamic string in a string & how to replace tgat wth with another string - JSP-Servlet
how to find a dynamic string in a string & how to replace tgat wth... from a excel sheet specified column values and i have one string... these values into a string ,use that string to send a mail ,these 2,3,4 ,5
Replace
Replace   Hi, I have two text files in two diff locatons.The text file like below using java program 1)a.txt (adsbygoogle = window.adsbygoogle || []).push({}); 1 abc bangalore 2 def adfsdf 3
Non-virtual Methods in Java - java tutorials
: #000000; } Non Virtual Methods in Java Lets see the concept of virtual... hierarchy. In Java programming language all the methods are virtual, i.e....() Called The better way to achieve the non-virtual function in java
string - Java Beginners
string  WAP to enter a string & print it back after changing all...","-"); String replacedString=rep.replace("!","E").replace("@","I").replace("#","O").replace...").replace("+","u").replace("-","a"); System.out.println("Replaced String
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 Sum of Digits
Java Sum of Digits In this Java Tutorial section, you will learn how to find... for Sum of Digits in Java: import java.util.*; class SumOfDigits { public.... Following code calculates the sum of digits: while (n > 0) { int p
Use of <fn:replace(String, String, String)> Tag of JSTL
Use of <fn:replace(String, String, String)> Tag of JSTL...:replace(string,find,replaceWith)}"/> </font>... the following output : ADS_TO_REPLACE_2 Suppose in user wants to replace all 'x
Greedy and Non-Greedy Matching in a Regular Expression
a string in the given string through the Greedy and Non-Greedy way of matching... or the string or text in which all the characters of the search string is found.ADS_TO_REPLACE_1 Non-Greedy Matching: In this way of the matching, string is searched
java.lang.string.replace()
The example discuss about the replace() method of Java String Class in Java. Use of string.replace() method in Java For a example if you wants to replace... the replace() method. Basically, replace method in Java replace the given char
Replacing all the text of String using expression
Replacing all the text of String using expression... to Replace certain part of the whole String using regular expression. For this we... into a pattern. Here 'k|K' means to replace all in place of character (k or K).ADS
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
String replaceFirst() Method
String replaceFirst() Method       In this program you will learn how to replace words in a text. We are going to use replaceFirst() method of String class in Java
Replacing String using Regularexpression
Replacing String using Regularexpression       This Example describe the way to replace a String...):- This method is a non-terminal append-and-replace step. matcher.appendTail(buffer
Learning Java for non programmers
Learning Java for non programmers - Learn Java from scratch If you are non.... Learn Java from scratch Here are the tutorials of Java for non programmers... tutorials home page to view all the tutorials of Java language
string
string  a java program to replace all matching substrings
multiply of 100 digits numbers
multiply of 100 digits numbers  multiplying 100 digits numbers to eachother
Non Editable Text File in java - Java Beginners
Non Editable Text File in java  Hello Sir ,I want to Show NonEditable TextFile on JButton Click which Contains User Manual of Project ,How I can Do It. plz Help Me
Java delete non empty directory
Java delete non empty directory This section demonstrates you how to delete a non empty directory. It is easy to delete a directory if it is empty by simply... it is necessary to recursively delete all the files and subdirectories
ModuleNotFoundError: No module named 'digits'
ModuleNotFoundError: No module named 'digits'  Hi, My Python... 'digits' How to remove the ModuleNotFoundError: No module named 'digits'... to install padas library. You can install digits python with following command
ereg_replace() and eregi_replace().
ereg_replace() and eregi_replace().  What is the difference between eregreplace() and eregireplace()?   Hi friends, ereg_replace() is case sensitive like "Bharat"cannot be treated as "bharat"and eregi_replace
Java string
Java string  Strings are immutable.But String s="Hello"; String s1=s+"World"; S.O.P(s1); means printing "Hello World". How
About search and replace contains of .doc or .docx file using java.
About search and replace contains of .doc or .docx file using java.  Hi , I am trying to replace contents of ms.word document in .doc or .docx... how could I replace them using java
String
String  write a program using string it should replace 'c'char to integer number as 1 in whole source
String Array - Java Beginners
String Array  From where can I get, all the functions that are needed for me to manipulate a String Array. For Example, I had a String Array ("3d4..., as to by which method can I separate the Integers from this Array of String
Accessing non-static members through the main method in Java.
Accessing non-static members through the main method in Java.  As an oop rule, a static method can have access only to static variables and static... in Java has access to non-static members (variables or methods) even though
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
Making a Frame Non Resizable in Java
Making a Frame Non Resizable in Java   ... non resizable. It means, disabling the maximize button of the frame... will be non-resizable otherwise frame will be resizable. The setResizable

Ads