重复的字符串,替换为scala

时间:2014-09-16 08:41:07

标签: regex scala

我有一个包含以下行的CSV文件:

val s = "\"a,b,c,d\",2,3,4"    // it also could have been "a,b,d",2,3,4 or "a,,d",2,3,4 ...
val regex = new Regex(
    "\"([^,]+)(,+([^,]*))+\"",
    "begin",
    "test", "end")
val line = regex.replaceAllIn(s, m => m.group("begin") + "#" + m.group("end"))

结果是:     a#d,2,3,4

但我想这样:a#b#c#d,2,3,4

有没有办法获得正则表达式检测到的所有值?

0 个答案:

没有答案