【发布时间】:2016-02-27 09:11:15
【问题描述】:
我需要用空字符串替换给定字符串中的子字符串,子字符串出现在字符串的不同位置。
我想从这些可能的字符串组合中删除"fruit":"apple",并期望得到相应的字符串:
{"client":"web","fruit":"apple"} --> {"client":"web"}
{"fruit":"apple","client":"web"} --> {"client":"web"}
{"client":"web","fruit":"apple","version":"v1.0"} --> {"client":"web","version":"v1.0"}
{"fruit":"apple"} --> null or empty string
我使用了regexp_replace(str, "\,*\"fruit\"\:\"apple\"", ""),但这并没有让我得到预期的结果。构造正则表达式的正确方法是什么?
【问题讨论】:
-
唯一的问题是
,后面的"fruit":"apple"? -
解码为 json,删除然后再次编码