Q:

Example of matches() function in Kotlin

0

matches() Function

The matches() function returns true if this char sequence matches the given regular expression.

Syntax:

infix fun CharSequence.matches(regex: Regex): Boolean

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 matches() function

// Example of matches() function
fun main()
{
	// Check entire string match
	val pattern = Regex("He([ll]+)o?")
    
	println(pattern.matches("Hello"))
	println(pattern.matches("Hellllllllllllllllo"))
	println(pattern.matches("HelloWorldHello"))
}

Output:

true
true
false

Explanation:

In the first two statements, strings contain the given pattern and in the third statement, the string doesn't contain the given pattern.

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

total answers (1)

Example of matchEntire() function in Kotlin... >>
<< Example of findAll() function in Kotlin...