fun findNextWord(text: String, expression: String) {
val escapedExpr = Regex.escape(expression)
val pattern = Regex("$escapedExpr\\s+(\\w+)")
val match = pattern.find(text)
if (match != null) {
println("The first word after '$expression' is: ${match.groupValues[1]}")
} else {
println("No match found!")
}
}
fun main() {
val text = "The quick brown fox jumps over the lazy dog."
val expression = "fox"
findNextWord(text, expression)
}
/*
run:
The first word after 'fox' is: jumps
*/