简体   繁体   中英

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

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 ?

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

Try this.Repalce by ``.See demo.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM