---
title: "Remove brackets character in java string"  
description: "Remove brackets character in java string"  
author: "Anonymous User"  
published: 2015-12-08  
updated: 2015-12-08  
canonical: https://www.mindstick.com/forum/33696/remove-brackets-character-in-java-string  
category: "java"  
tags: ["java", "string"]  
reading_time: 1 minute  

---

# Remove brackets character in java string

I want to [remove](https://yourviews.mindstick.com/story/4554/8-harmful-weeds-to-remove-from-garden) all type of brackets [character](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) (example: [],(),{}) in [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) by using java.\
I am doing it like this :\

```
String test = "watching tv (at home)"; test = test.replaceAll("(","");test = test.replaceAll(")","");
```

\
But its not working . [Suggest me](https://www.mindstick.com/interview/23114/can-you-suggest-me-few-top-directory-submission-site) a solution please.

## Replies

### Reply by Anonymous User

To remove all punctuation marks that include all brackets, braces and sq. brackets ... as per the question is:\

```
String test = "watching tv (at home)"; test = test.replaceAll("\\p{P}","");
```

But this solution removes also symbols like ., ,, ;, etc\
\
The first argument of replaceAll takes a regular expression.\
All the brackets have meaning in regex: Brackets are used in regex to reference capturing groups, square brackets are used for character class & braces are used for matched character occurrence. Therefore they all need to be escaped...However here the characters can simply be enclosed in a character class with just escaping required for square brackets\

```
test = test.replaceAll("[\\[\\](){}]","");
```


---

Original Source: https://www.mindstick.com/forum/33696/remove-brackets-character-in-java-string

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
