[英]Scala pattern patching to replace every second occurrence
I have a string that looks like the one below.我有一个看起来像下面的字符串。
{"module":"page1":"action":"save":"FirstName":"John”}
I would like to replace every second ":" into "," to make it a valid JSON.我想将每一秒的“:”替换为“,”以使其成为有效的 JSON。
Could somebody please suggest on how I can achieve this scala.有人可以建议我如何实现这个 scala。 In this example, there are only 3 key=value pairs, but there can be more than 3 as well.
在此示例中,只有 3 个 key=value 对,但也可以超过 3 个。
Expected:预期的:
{"module":"page1","action":"save","FirstName":"John”}
Thanks in advance提前致谢
-JC -JC
This should do it.这应该这样做。
"""("\w*":"\w*"):""".r.replaceAllIn(str, "$1,")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.