remove bracket, double quote, and possibly add space using string.replaceall in java

I saw multiple thread answering about how to replace/remove single quote (‘), double quote (“), bracket ([,{), commas, etc. While I was able to successfully remove them, but I would like to understand more. For example, string.replaceAll(“p{P}”,””); can remove the punctuations. I am confused about this syntax; how does “p{P}”,”” is equal to punctuations?

I have a string that I would like to remove bracket, double quote, and possibly add space. As shown below, I would like to use replaceAll to change my string from category to updatedCategory.

String category = "["restaurant","bar","burger joint"]";
String updatedCategory = "restaurant, bar, burger joint";

Answer

You need to learn about regex, for your problem you can use replaceAll with this regex ["[ ]] like this:

category.replaceAll("["\[ \]]", "")

The output will be:

restaurant,bar,burgerjoint

So to get the same updatedCategory just use:

category.replaceAll("["\[ \]]", "")
    .replace(",", ", ")