import scala.util.matching.Regex
object ReplaceQuestionMarks extends App {
val str = "What??? Why?? How?????"
// Define regex pattern to match one or more '?'
val pattern: Regex = "\\?+".r
// Replace all matches with a single '?'
val result = pattern.replaceAllIn(str, "?")
println(result)
}
/*
run:
What? Why? How?
*/