0
从来就一直在看这个例子部分matcing正则表达式使用hitEnd斯卡拉
String[] ss = { "aabb", "aa", "cc", "aac" };
Pattern p = Pattern.compile("aabb");
Matcher m = p.matcher("");
for (String s : ss) {
m.reset(s);
if (m.matches()) {
System.out.printf("%-4s : match%n", s);
}
else if (m.hitEnd()) {
System.out.printf("%-4s : partial match%n", s);
}
else {
System.out.printf("%-4s : no match%n", s);
}
}
而且我想用,hitEnd
我的Scala模式匹配的正则表达式
val VERSION = "([0-2].0)"
val MESSAGE = s"A message with version $VERSION".r
def checkMessage(action: String): Boolean = {
action match {
case MESSAGE(version) => true
case _ => false
}
}
我想要什么如果某人输入A message with version 3.0
告诉他该邮件有部分匹配,但他输入的版本不正确。
任何想法如何在scala中使用hitEnd
?
问候