guys, I’m a bit confused with kotlin’s Regex from ...
# getting-started
e
guys, I’m a bit confused with kotlin’s Regex from std lib. For example: I need to find all occurrences of numbers in str. And I don’t understand, why I can do that in two very similar ways?
Copy code
val str = "text here 123 and more text 456"
val regex = Regex("[0-9]+")
way 1)
Copy code
var matchRes = regex.find(str)
while (matchRes != null) {
	println(matchRes.value)
	matchRes = matchRes.next()
}
way 2)
Copy code
val matchRes = regex.findAll(str)
for (i in matchRes) {
	println(i.value)
}
What’s the difference? May be
matchRes.next()
is not lazy, and
for (i in matchRes) {
is?