Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何仅在某个正则表达式段匹配时匹配整个正则表达式?_Regex_Json - Fatal编程技术网

Regex 如何仅在某个正则表达式段匹配时匹配整个正则表达式?

Regex 如何仅在某个正则表达式段匹配时匹配整个正则表达式?,regex,json,Regex,Json,例如,我想在这里匹配_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","_typ

例如,我想在这里匹配_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,这是我不想要的。我离你很近吗?任何帮助都将不胜感激。

使用JSON解析器会容易得多,但
*
意味着(零或更多)。使用
+
(一个或多个)


是的,空字符串匹配
(任何内容)*{1,}

为什么不解析JSON呢?太棒了,成功了!谢谢,我对regex还比较陌生,所以有时候我还是会被难倒。
"_msg":"([^"]+)"