Scala String matches() method with example
Last Updated :
03 Oct, 2019
The matches() method is used to check if the string stated matches the specified regular expression in the argument or not.
Method Definition: Boolean matches(String regex)
Return Type: It returns true if the string matches the regular expression else it returns false.
Example #1:
object GfG
{
def main(args : Array[String])
{
val result = "Preeti" .matches( ".*i" )
println(result)
}
}
|
So, here the regular expression matches the string stated. So, it returns true.
Example #2:
object GfG
{
def main(args : Array[String])
{
val result = "Preeti" .matches( ".i.*" )
println(result)
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...