使用正则表达式提取值形式 JSON 负载
Extract Value form JSON Payload using regular expression
我有以下负载
{
"has_error":false,
"error_info":{
},
"count":[
372684,
200565
],
"total_count":3095459
}
只需要获取计数中的第二个值,即 200565
。
尝试使用以下正则表达式 \[([^\]]+)\]
但它正在从计数中获取两个值。
尝试了 JSON 路径提取器,并且在那个 $.count[*]
中,它也提取了两个值。我怎样才能获取第二个值?
使用
\[[^\]]*\b(\d+)\s*\]
参见proof。
解释
--------------------------------------------------------------------------------
\[ '['
--------------------------------------------------------------------------------
[^\]]* any character except: '\]' (0 or more
times (matching the most amount possible))
--------------------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char
--------------------------------------------------------------------------------
( group and capture to :
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
) end of
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\] ']'
我有以下负载
{
"has_error":false,
"error_info":{
},
"count":[
372684,
200565
],
"total_count":3095459
}
只需要获取计数中的第二个值,即 200565
。
尝试使用以下正则表达式 \[([^\]]+)\]
但它正在从计数中获取两个值。
尝试了 JSON 路径提取器,并且在那个 $.count[*]
中,它也提取了两个值。我怎样才能获取第二个值?
使用
\[[^\]]*\b(\d+)\s*\]
参见proof。
解释
--------------------------------------------------------------------------------
\[ '['
--------------------------------------------------------------------------------
[^\]]* any character except: '\]' (0 or more
times (matching the most amount possible))
--------------------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char
--------------------------------------------------------------------------------
( group and capture to :
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
) end of
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\] ']'