W3cubDocs

/Kotlin

findAll

Platform and version requirements: JVM (1.0), JS (1.1)
fun findAll(
    input: CharSequence, 
    startIndex: Int = 0
): Sequence<MatchResult>
Platform and version requirements: Native (1.3)
fun findAll(
    input: CharSequence, 
    startIndex: Int
): Sequence<MatchResult>
For JVM, JS

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



fun main(args: Array<String>) {
//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
}

Exceptions

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

For Common

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



fun main(args: Array<String>) {
//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
}
For Native

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

Exceptions

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

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/-regex/find-all.html