Scala/Java/Kotlin: How to replace left and right brackets in a String (replaceFirst, replaceAll)
Briefly

If you're using Scala, Java, Kotlin, or other JVM languages, and need to replace left or right brackets in a String, use '\' before the left bracket, no escape character before the right bracket. The examples illustrated demonstrate how to effectively replace brackets using 'replaceFirst' and 'replaceAll' methods.
With 'replaceFirst,' the first instance of [test] gets removed, while 'replaceAll' eliminates all occurrences. These methods can be utilized in Scala, Java, or Kotlin interchangeably.
Read at Alvinalexander
[
add
]
[
|
|
]