Scala - 正则表达式匹配例子

壹Try胜仟言

别忘了 import scala.util.matching._

 

scala> var s = "a_b_c_d_e"
s: String = a_b_c_d_e

scala> val regex = new Regex("^([^_]*)_([^_]*)_([^_]*)_(.*)$")
regex: scala.util.matching.Regex = ^([^_]*)_([^_]*)_([^_]*)_(.*)$

scala> val regex(time, user,cust,ss ) = s
time: String = a
user: String = b
cust: String = c
ss: String = d_e

posted @ 2016-01-21 17:24  LightingCui  阅读(792)  评论(0编辑  收藏  举报