ADVERTISEMENT
ADVERTISEMENT

Example of matches() function in Kotlin

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

matches() Function

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

Syntax:

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

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.

Kotlin Regular Expression (Regex) Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.