I want to replace all special characters from the string object BusDetails below with a blank "" except for _(underscore) and numbers in java ?
BusDetails=BusDetails.replaceAll("—", "").replaceAll("\\s+","_").replaceAll("ROUTE", "BUS").replaceAll("-", "_");
BusDetails = BusDetails.replaceAll("[^a-zA-Z0-9_-]", "");
Using the regex pattern "[^a-zA-Z0-9_-]"
we can replace all special characters (symbols) from the string except letters, numbers and '_'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With