如果我有一个列表s = '["a", "b", "c"]'
的字符串表示,我如何解析此字符串以提取列表对象?预期输出l = ["a", "b", "c"]
答案 0 :(得分:1)
val str = """["a","b" "c"]""" // string with quote marks
val getStrs = "\"([^, ]+)\"".r // regex to isolate quoted strings
现在将引用的字符串(不带引号)拉入List[String]
。
val lst = (for (m <- getStrs findAllMatchIn str) yield m group 1).toList
// lst: List[String] = List(a, b, c)