正则表达式获取单词后匹配单词

时间:2017-06-01 04:39:14

标签: regex regex-greedy regex-group

在下面的内容中,我需要正则表达式来获取匹配后的提交内容值"提交": 请建议使用正则表达式来实现这一目标。

" {"提交" {" ID":" f0180cb5d2f71906bc3875f3526a85c73cd4bf35"" short_id":" f0180cb5& #34;," title":"更新Jenkinsfile"," author_name":"管理员"," author_email": #&34; abc@mail.com"," created_at":" 2017-05-31T07:15:59.000 + 00:00""消息&#34 ;:"更新Jenkins文件"},"提交":[{" id":" f0180cb5d2f71906bc3875f3526a85c73cd4bf35"," short_id& #34;:" f0180cb5"," title":"更新Jenkinsfile"," author_name":"管理员", " AUTHOR_EMAIL":" admin@mail.com"," created_at":" 2017-05-31T07:15:59.000 + 00:00&#34 ;,"消息":"更新Jenkinsfile"}],"差异":[{" old_path":&#34 ; Jenkinsfile"" new_path":" Jenkinsfile"" a_mode":" 100644"" b_mode" :" 100644"," diff":" --- a / Jenkinsfile \ n +++ b / Jenkinsfile \ n @@ -2,6 +2, 7 @@ node(' Infrastructure')\ n {\ n \ n \ n + // test \ n stage' Checkout' \ n尝试\ n {\ t \ n"," new_file":false," renamed_file":false," deleted_file":false}],& #34; compare_timeout":假," compare_same_ref":假}"

1 个答案:

答案 0 :(得分:0)

此正则表达式将捕获"commits":的数组值。

请注意,要使其生效,"commits"的值必须是对象数组(以[{开头,以}]结尾。

我赞同William Cross的观点,为什么你要试用正则表达式JSON。解析它以访问commits的值。

会更安全

查看有效的regex example here

/"commits":(\[\{.*?\}\])/g
相关问题