0

I have a stream, which has the following expression:

.map(l -> l.replaceAll("[,.!?:;]", "")

As you can see I want to take a string, and if a string contains one of the values ,.!?:; I want to remove them.

I also want to remove These two symbols: [ ]

When I add it in the sequence:

.map(l -> l.replaceAll("[,.!?[]:;]", "")

The idea gives me an error, unclosed character class. How can I include these two symbols in the sequence as well?

user16320675
  • 121
  • 1
  • 2
  • 8

1 Answers1

1

You escape special characters with \. Note that \ is itself a special character. So something like

.map(l -> l.replaceAll("[,.!?\\[\\]:;]", "")
Elliott Frisch
  • 191,680
  • 20
  • 149
  • 239