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

你可能感兴趣的:(Scala - 正则表达式匹配例子)