I want to delete all "key":null
patterns from json string.
String jsonStr = "{\"a\":null,\"b\":1,\"c\":null,\"d\":5}";
System.out.println(jsonStr.replaceAll("\".*?\":null,", ""));
I expected
{"b":1,"d":5}
But result is
{"d":5}
Obviously, non greedy is not applied.
I tried with Pattern
, Matcher
. But it also results in same result.
Pattern replace = Pattern.compile("\".*?\":null,");
Matcher matcher = replace.matcher(jsonStr);
System.out.println(matcher.replaceAll(""));