Q:

Example of matchEntire() function in Kotlin

0

matchEntire() Function

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?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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)
}

Output:

Hello
null
null
Hello
Hello, Boss!
null

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Example of replace() function in Kotlin... >>
<< Example of matches() function in Kotlin...