例如,我想在这里匹配_msg对象:
{"message":{"_id":"","_obj":"","_obj_type":"1","_type":"ERROR","_msg":"An error has occurred!","_user":"","_added":"","_func":"Document Uploaded","_action":""}, "data":[]}
但不在这里:
{"message":{"_id":"","_obj":"","_obj_type":"1","_type":"ERROR","_msg":"","_user":"","_added":"","_func":"Document Uploaded","_action":""}, "data":[]}
因为要显示实际消息。这是我尝试的正则表达式:
"_msg"\:"([^"]*){1,}"
然而,它仍然匹配一个空的_msg,我不想要。我甚至关闭了吗?任何帮助将不胜感激。
答案 0 :(得分:2)
使用JSON解析器要容易得多,但*
表示(零或更多)。使用+
(一个或多个)。
"_msg":"([^"]+)"
是空字符串匹配(anything)*{1,}