[英]Java String delete part of string
I have a Java String like this我有一个这样的 Java 字符串
"functional_type":"endpoint","configuration":[],"neighbours":{ "1": {"id":1,"name": "ep"}}},
And I wish to replace this part我想更换这部分
"neighbours":{ "1": {
with another string.用另一个字符串。 Moreover the number one is could be any number like for example
23
or 1903434
in order to have at the end this:此外,第一个可以是任何数字,例如
23
或1903434
,以便在最后得到:
"functional_type":"endpoint","configuration":[],"filed":{"id":1,"name": "ep"}}},
You should escape "{".你应该转义“{”。
String s = "\"functional_type\":\"endpoint\",\"configuration\":[],\"neighbours\":{ \"1\": {\"id\":1,\"name\": \"ep\"}}},";
System.out.println(s.replaceAll("\"neighbours\":\\{ \"\\d+\": \\{", "\"filed\":{"));
result:结果:
"functional_type":"endpoint","configuration":[],"filed":{"id":1,"name": "ep"}}},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.