I am splitting a string by a repeatable delimiter, and am also intended to keep the delimiters as well.
val str = "xxoooooooxxoxoxooooo"
val reg = Regex("(?<=x+)|(?=x+)")
var list = str.split(reg)
println(list)
The output is [, x, x, ooooooo, x, x, o, x, o, x, ooooo]
, though I would like to get
[xx, ooooooo, xx, o, x, o, x, ooooo]
val str = "xxoooooooxxoxoxooooo"
val reg = Regex("o+|x+").findAll(str).map { it.value }.toList()
println(reg)
//[xx, ooooooo, xx, o, x, o, x, ooooo]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With