Share on Google+Share on Google+

Deepak Kumar
Java replace all non alphanumeric
1 Answer(s)      6 years and a month ago
Posted in : Java Beginners

Hi,

In Java how to replace all non alphanumeric characters with blank? Share me the best code for java replace all non alphanumeric.

Thanks

Ads

View Answers

March 29, 2011 at 11:36 AM


Hi,

You can use the replaceAll() function of String class in Java.

We will use the regular expression "[^a-zA-Z0-9]" for finding all non alphanumeric characters and then replace it with required character.

Following example show how to replace all non alphanumeric characters present in a Java String variable.

public class TestReplaceAllNonAlphanumeric 
{
    public static void main(String[] args) 
    {
    String s = "What is use of[]. What {} is used.";
    s = s.replaceAll("[^a-zA-Z0-9]", "");
    System.out.println(s);
    }
}

Thanks










Related Tutorials/Questions & Answers:
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
MySQL replace all non alphanumeric characters
MySQL replace all non alphanumeric characters  Hi, How to replace all non alphanumeric characters in MySQL? Thanks
Advertisements
Java String : Replace All
Java String : Replace All This section defines how to replace all character with specified character without using system methods. Replace All method : You can replace all specific character in a given string with another character
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
how to get string after first occurence of alphanumeric char in java?
how to get string after first occurence of alphanumeric char in java?  how to get string after first occurence of alphanumeric char in java For Example : String = "13(i),145afc34df,1ss,kk,90"; Required output : 13 (i
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
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.
javascript regex validation alphanumeric
regex validation for alphanumeric?   <html> <head> <title> alphanumeric validation using regex</title> <script type="text...}$/; if (pattern.test(name)) { alert(name +" has alphanumeric value
Alphanumeric Validation in JavaScript
Alphanumeric Validation in JavaScript In this tutorials we will discuss about alphanumeric validation in JavaScript. Sometimes it may occur when user have... to validate a form which can accept only character and digit in java Script
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
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... any one tell me how could I replace them using java
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 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
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 script to replace words starting and ending with tild(~) symbol in a text area with the word highlighted yellow.
java script to replace words starting and ending with tild(~) symbol in a text... requirement we have to replace all the occurence of such words and replace with highlighted text. for example: The script should findout all the occurence of the words
Replace TEXT
Replace TEXT   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
Making a Frame Non Resizable in Java
Making a Frame Non Resizable in Java       This program illustrates you how to make a frame non... the boolean value false to the setResizable() method then the frame will be non
Java Print the all components
Java Print the all components  This is my code. Please tell me the solutions import javax.swing.table.*; import javax.swing.*; import java.util.*; import java.awt.*; import java.awt.event.*; import java.awt.print.*; import
hi all - Java Beginners
hi all  hi, i need interview questions of the java asap can u please sendme to my mail   Hi, Hope you didnt have this eBook. You can download this at thislink... http://www.4shared.com/file/45195248/1f297b96
Making a Frame Non Resizable in Java
Making a Frame Non Resizable in Java   ... a frame non resizable. It means that the disabling the maximize button... then the frame will be non-resizable otherwise frame will be resizable
How to retrieve kernal memory details(paged and non-paged ) using SIGAR API in java program
How to retrieve kernal memory details(paged and non-paged ) using SIGAR API in java program  I need to get all memory details of task manager(OS... and non-paged) and all as I indicated in image below.) I am using SIGAR API. I
MySQL Replace
MySQL Replace       MySQL Replace function finds and replaces the occurrences of specified string...: REPLACE( String_Text, String_FROM, String_TO); where String_Text
What is the difference between ereg_replace() and eregi_replace()?
What is the difference between ereg_replace() and eregi_replace()?  What is the difference between eregreplace() and eregireplace
replace character in php
replace character in php  PHP script that replace character
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
non empty file
Java Delete non empty file  f.delete() works when the file is empty.if a file be non empty how to delete it???   Please visit the following link: http://www.roseindia.net/tutorial/java/core/files
how to split string after first occurrence of alphanumeric character?
how to split string after first occurrence of alphanumeric character?  String strArray="135(i),15a,14(g)(q)12,67dd(),kk,159";//splited by ',' divide string after first occurrence of alphanumeric value/character expected output
regexp_replace in update and replace query in postgres
regexp_replace in update and replace query in postgres  update message set data = replace (data, 'wmost','westernmost'); April 4, 2011 at 5:04 PM.... is there a way to avoid this problem. Can you send similar query using regexp_replace
Difference between translate and replace
Difference between translate and replace   hiii, What is the difference between translate and replace?   hello, Replace replace every.... this work for entire word and pattern,. Translate replace the one charecte
clustered and a non-clustered index?
clustered and a non-clustered index?  What is the difference between clustered and a non-clustered index
Non SOAP webservices - WebSevices
Non SOAP webservices  How can i build non-SOAP (XML) based... option other than REST to implement non-soap webservices? Do we have WSDL incase of non-soap webservices
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads