findAll

expect fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult>(source)(source)
actual fun findAll(input: CharSequence, startIndex: Int = 0): Sequence<MatchResult>(source)(source)

Returns a sequence of all occurrences of a regular expression within the input string, beginning at the specified startIndex.

Since Kotlin

1.0

Throws

if startIndex is less than zero or greater than the length of the input char sequence.

Samples


fun main() { 
   //sampleStart 
   val text = "Hello Alice. Hello Bob. Hello Eve."
val regex = Regex("Hello (.*?)[.]")
val matches = regex.findAll(text)
val names = matches.map { it.groupValues[1] }.joinToString()
println(names) // Alice, Bob, Eve 
   //sampleEnd
}