在
Scala中,我有一个正则表达式模式匹配,如下所示:
val Regex = """(\d{4})/(\d{2})/(\d{2})""".r val Regex(year,month,day) = "2013/01/06"
结果是:
year: String = 2013 month: String = 01 day: String = 06
如何在Haskell中完成类似的结果?换句话说,我可以匹配包含组的正则表达式并将组分配给标识符吗?
这对我有用:
Prelude Text.Regex.Posix> "2013/01/06" =~ "([0-9]+)/([0-9]*)/([0-9]*)" :: (String,String,[String]) ("","2013/01/06","",["2013","01","06"])
(OS X上的ghci 7.4.2)