paresh
paresh

Reputation: 351

Regex to remove

Need regex to remove \" and '

 String date="\"CCB \\\"E Safety\\\" Internet Banking security components 3.0.7.0\"'Configuration & \\\"Service Tool v3.02.00'"

Reuslt String : CCB E Safety Internet Banking security components 3.0.7.0. Configuration & Service Tool v3.02.00

Im using this

System.out.println(date.replaceAll("[\\W+]", " ").replaceAll("\\s+", " "));

But it removes dot also

CCB E Safety Internet Banking security components 3 0 7 0 Configuration Service Tool v3 02 00

Upvotes: 0

Views: 98

Answers (2)

Bohemian
Bohemian

Reputation: 424983

Don't use regex!

The characters you want to remove can be removed without using regex, and it's a whole lot easier to read:

data = data.replace("\"", " ").replace("'", " ").trim();

In case you are wondering, replace() still replaces all occurrences, but the search parameter is just plain text, whereas replaceAll() uses a regex search parameter.

Upvotes: 0

zhh
zhh

Reputation: 2406

data = date.replaceAll("[\\\\\"'\\s]+", " ").trim();

Result

CCB E Safety Internet Banking security components 3.0.7.0 Configuration & Service Tool v3.02.00 

Upvotes: 2

Related Questions