Yes, you can use String.replaceAll
which takes a regex:
String input = "BAD good {} []";
String output = input.replaceAll("[^a-z0-9\\[\\]]", "");
System.out.println(output); // good[]
Or in Guava you could use a CharMatcher
:
CharMatcher matcher = CharMatcher.inRange('a', 'z')
.or(CharMatcher.inRange('0', '9'))
.or(CharMatcher.anyOf("[]"));
String input = "BAD good {} []";
String output = matcher.retainFrom(input);
That just shows the lower case version, making it easier to demonstrate. To include upper case letters, use "[^A-Za-z0-9\\[\\]]"
in the regex (and any other symbols you want) - and for the CharMatcher
you can or
it with CharMatcher.inRange('A', 'Z')
.