Strings are immutable in Java. Make sure you re-assign the return value to the same String
variable:
str = str.replaceAll("\\[", "");
For the normal replace
method, you don’t need to escape the bracket:
str = str.replace("[", "");
More Related Contents:
- Java how to replace 2 or more spaces with single space in string and delete leading and trailing spaces
- How can non-ASCII characters be removed from a string?
- Replace the last part of a string
- String.replaceAll is considerably slower than doing the job yourself
- Remove all occurrences of \ from string
- Replace a character specific number of times in String Java
- Replace a character at a specific index in a string?
- Regex to match a C-style multiline comment
- Difference between String replace() and replaceAll()
- Splitting a string at every n-th character
- How to extract numbers from a string and get an array of ints?
- Java – Best way to grab ALL Strings between two Strings? (regex?)
- How do I convert CamelCase into human-readable names in Java?
- Check and extract a number from a String in Java
- Can I replace groups in Java regex?
- Extracting pairs of words using String.split()
- What is the simplest way to convert a Java string from all caps (words separated by underscores) to CamelCase (no word separators)?
- Why String.replaceAll() in java requires 4 slashes “\\\\” in regex to actually replace “\”?
- Java String.split() Regex
- Why does String.replace not work? [duplicate]
- String replace a Backslash
- Remove all empty lines
- Split a string, at every nth position
- Java String.split() sometimes giving blank strings
- Java String ReplaceAll method giving illegal repetition error?
- Find all words with 3 letters with regex
- Regular Expressions on Punctuation
- Split string into repeated characters
- Parse Date from String in this format : dd/MM/yyyy [to dd/MM/yyyy]
- Java replace all square brackets in a string