我想解析git shortstat行。 E.g。
val in = """ 6 files changed, 55 insertions(+), 1 deletions(-)"""
val out = (6, 55, 1)
如何从out
获取in
?我试过regexp,但可能搞错了:
import util.Try
val Ex = """ (\d+) files changed, (\d+) insertions\(+\), (\d+) deletions\(-\)""".r
def parse(line: String): Option[(Int, Int, Int)] = line match {
case Ex(a, b, c) => (for {
ai <- Try(a.toInt)
bi <- Try(b.toInt)
ci <- Try(c.toInt)
}
yield (ai, bi, ci)).toOption
case _ => None
}
但是出了点问题:parse(in) == None
......
答案 0 :(得分:0)
需要逃避+
:
// !!
val Ex = """ (\d+) files changed, (\d+) insertions\(\+\), (\d+) deletions\(-\)""".r