Kotlin program to demonstrate the example of findAll() function
// Example of findAll() function
fun main()
{
// Regex to match a 5 letters pattern
// beginning with He
val pattern = Regex("He...")
val res1 : Sequence<MatchResult> = pattern.findAll("Hello, World!", 0)
// Prints all the matches using forEach loop
res1.forEach()
{
matchResult -> println(matchResult.value)
}
println()
val res2 : Sequence<MatchResult> = pattern.findAll("Hello, I'm saying Hello Boss!", 0)
// Prints all the matches using forEach loop
res2.forEach()
{
matchResult -> println(matchResult.value)
}
println()
}
Output:
Hello
Hello
Hello
Explanation:
In the first statement "Hello" is there one time, and in the second statement "Hello" is there two times.
Kotlin program to demonstrate the example of findAll() function
Output:
Explanation:
In the first statement "Hello" is there one time, and in the second statement "Hello" is there two times.
need an explanation for this answer? contact us directly to get an explanation for this answer