New to Scala, I've written this piece of code to match IP addresses, but results with "No Match".
val regex = """^(([0-9])|([1-9][0-9])|(1([0-9]{2}))|(2[0-4][0-9])|(25[0-5]))((\.(([0-9])|([1-9][0-9])|(1([0-9]{2}))|(2[0-4][0-9])|(25[0-5]))){3})$""".r
val i = "10.20.30.40"
def isValidIP(ip: String) = ip match {
case regex(ip) => println(ip)
case _ => println("No match.")
}
isValidIP(i)
Result: No match.
I have verified that the Regex pattern works as expected.
What am I missing here?