There are five functions in that we use commonly.
Let us see them in detail :
"Cool Guy"
'u|o'
fun main() { var str = "Cool Guy" var x = Regex("u|o") val match = x.findAll(str) match.forEach { word -> println("The string has : "+word.value) } if (x.containsMatchIn(str)) { println("Found a match") } else { println("Did not find a match") } }
var x = Regex("u|o")
val match = x.findAll(str)
var str = "Cool Guy"
The string has : o The string has : o The string has : u
fun main() { var str = "Cool Guy" var x = Regex("u|o") val match = x.find(str) println("The Match Result is : "+match) if (x.containsMatchIn(str)) { println("Found a match") } else { println("Did not find a match") } }
kotlin.text.MatcherMatchResult@6cd8737
match='o'
fun main() { var str = "Cool Guy" var x = Regex("u|o") val match = x.find(str) if (match != null) { println("The Match Result is : "+match.value) } if (x.containsMatchIn(str)) { println("Found a match") } else { println("Did not find a match") } }
val match = x.find(str)
println("The Match Result is : "+match.value)
"Hello Beautiful World"
fun main() { var str = "Hello Beautiful World" var x = Regex("\\s") val match = x.split(str) match.forEach { word -> println("The string has : "+word) } }
var x = Regex("\\s")
val match = x.split(str)
match.forEach { word -> println("The string has : "+word) }
The string has : Hello The string has : Beautiful The string has : World
"Hello Beautiful World"
"Hello:Beautiful:World"
fun main() { var str = "Hello Beautiful World" var x = Regex("\\s") val match = x.replace(str, ":") println("The new String is : "+match) }
var x = Regex("\\s")
val match = x.replace(str, ":")
The new String is : Hello:Beautiful:World