IntermediateStandard Library
Regex Find
Find a pattern in text using Regex.
kotlin
fun main() {
val text = "Order ID: 12345"
val regex = "\\d+".toRegex()
val result = regex.find(text)?.value
println(result)
}Output
12345
Explanation
\d+ matches one or more digits. find() returns the first match. .value gives the matched string.