Scala regex pattern match of ip address
问题 I can't understand why this code returns false: val reg = """.*(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}).*""".r "ttt20.30.4.140ttt" match{ case reg(one, two, three, four) => if (host == one + "." + two + "." + three + "." + four) true else false case _ => false } and only if I change it to: val reg = """.*(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}).*""".r "20.30.4.140" match{ case reg(one, two, three, four) => if (host == one + "." + two + "." + three + "." + four) true else false case _ =>