[英]I want to extract a particular part or values from the string using regex
My String is something like in this pattern:我的字符串类似于这种模式:
{ "x_y_z":{data}, "a_b_c_d":{[my data]}, "q_w_e":{data} }
Data I want to extract is:我要提取的数据是:
{[my data]}
Could point me into a direction how to achieve this?能否指出我如何实现这一目标?
Using a JSON parser is a more robust and readable way to go, but to answer the question:使用 JSON 解析器是一种更健壮和可读的方法,但要回答这个问题:
String abcd = str.replaceAll(".*\"a_b_c_d\"\\s*:\\s*(.*?)\\s*,.*", "$1");
The regex matches the entire input and captures the target as group 1, and the replacement is the captured group.正则表达式匹配整个输入并将目标捕获为组 1,替换为捕获的组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.