我有这个json字符串{“last\u nm”:“难以辨认”,“ful\u nm”:“}下面是替换代码,我试图在scala中删除上面json中多余的双引号,但它不起作用。
replace(":\"\"[a-z]+\"\"",":\"[a-z]+\"")
ufj5ltwl1#
您可以使用正则表达式捕获组,方法是将正则表达式括在省略号中- (some_regex) ,然后用 $x (x=组号)。例如:
(some_regex)
$x
scala> val str = "{\"LAST_NM\":\"\"ILLEGIBLE\"\",\"FULL_NM\":\"\",\"FIRST_NAME\":\"\"NOT_SUPPLIED\"\"}" str: String = {"LAST_NM":""ILLEGIBLE"","FULL_NM":"","FIRST_NAME":""NOT_SUPPLIED""} scala> str.replaceAll("\"(\"[^\\,]+?\")\"","$1") res5: String = {"LAST_NM":"ILLEGIBLE","FULL_NM":"","FIRST_NAME":"NOT_SUPPLIED"}
1条答案
按热度按时间ufj5ltwl1#
您可以使用正则表达式捕获组,方法是将正则表达式括在省略号中-
(some_regex)
,然后用$x
(x=组号)。例如: