0
我想基於正則表達式匹配自動將字符串轉換爲日期。我的代碼到目前爲止是如下:斯卡拉地圖[正則表達式,字符串] collectFirst錯誤
package be.folks.date
import java.util.Date
import scala.util.matching.Regex
import org.joda.time.format.DateTimeFormat
class StringToDate(underlying:String) {
val regmap : Map[Regex, String] = Map(
("""\d\d-\d\d-\d\d\d\d""".r, "dd-MM-yyyy"),
("""\d\d-\w\w\w-\d\d\d\d""".r, "dd-MMM-yyyy")
)
def toDate() : Date = {
DateTimeFormat.forPattern((regmap collectFirst { case (_(underlying) , v) => v } get)).parseDateTime(underlying).toDate()
}
}
object StringToDate {
implicit def +(s:String) = new StringToDate(s)
}
不過,我得到一個錯誤「_」 - 但卻發現()
我該如何解決這個
我打算把它留在例外:) – 0n4li