Why there is a match here:
scala> """\bdog\b""".r
res65: scala.util.matching.Regex = \bdog\b
scala> res65.findFirstIn(" The dog plays in the yard")
res66: Option[String] = Some(dog)
But not here:
scala> "The dog plays in the yard".matches("""\bdog\b""")
res67: Boolean = false
?
In the second case, the whole stirng has to match the regex, in the first case, any part of the string can match. Compare the second case to this:
"The dog plays in the yard".matches(""".*\bdog\b.*""")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With