ADVERTISEMENT
ADVERTISEMENT

Example of matchEntire() function in Kotlin

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

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?

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

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.