Ravi_Parmar
Ravi_Parmar

Reputation: 12329

Unable to replace String containing special characters

I want to replace all special characters with whitespace but I am unable to replace x :

String search = "640×20141007151608@#$%$20141008104817.jpeg";
String newSearch = search.replaceAll("[\\p{Punct}&&[^_]]", "");
System.out.println(newSearch);

output : 640×2014100715160820141008104817jpeg

Upvotes: 0

Views: 170

Answers (2)

vks
vks

Reputation: 67968

[^0-9a-zA-Z\.]

Try this.Repalce by ``.See demo.

http://regex101.com/r/hQ1rP0/51

Upvotes: 0

Erran Morad
Erran Morad

Reputation: 4743

I use the logic below:

String newSearch = search.replaceAll("[^A-Za-z0-9 ]","");

That is, remove anything that is not a number or a digit. Is this what you wanted ?

Upvotes: 4

Related Questions