The matchEntire() function is used to match the entire given string against the pattern and returns an instance of MatchResult if the entire input string matches; null, otherwise.
Syntax:
fun matchEntire(input: CharSequence): MatchResult?
Kotlin program to demonstrate the example of matchEntire() function
// Example of matchEntire() function
fun main()
{
// Check entire string match
var pattern = Regex("Hello?")
println(pattern.matchEntire("Hello")?.value)
println(pattern.matchEntire("Helllllo")?.value)
println(pattern.matchEntire("Hello, World!")?.value)
pattern = Regex("""\D+""")
println(pattern.matchEntire("Hello")?.value)
println(pattern.matchEntire("Hello, Boss!")?.value)
println(pattern.matchEntire("Hello101")?.value)
}
Kotlin program to demonstrate the example of matchEntire() function
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer