Example of containsMatchIn() function in Kotlin

Learn about the containsMatchIn() function in Kotlin, and demonstrate the example of containsMatchIn() function.
Submitted by IncludeHelp, on March 25, 2022

containsMatchIn() Function

The containsMatchIn() function is used to check whether there exists any match of our pattern in the input and returns a boolean value.

Syntax:

fun containsMatchIn(input: CharSequence): Boolean

Kotlin program to demonstrate the example of containsMatchIn() function

// Example of containsMatchIn() function
fun main()
{
	// Regex to match any string starting with 'i'
	val pattern = Regex("^i")
    
	println(pattern.containsMatchIn("includehelp"))
	println(pattern.containsMatchIn("Incognito"))
}

Output:

true
false

Explanation:

The first string ("includehelp") starts with "i" and the second string ("Incognito") starts with "I". Thus, the output is true and false.

Kotlin Regular Expression (Regex) Programs »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.