【发布时间】:2017-06-01 04:39:14
【问题描述】:
在下面的内容中,我需要正则表达式来获取匹配后的提交内容值 "commits": 请建议正则表达式模式以实现这一目标。
"{"commit":{"id":"f0180cb5d2f71906bc3875f3526a85c73cd4bf35","short_id":"f0180cb5","title":"更新 Jenkinsfile","author_name":"Administrator","author_email":"abc@ mail.com","created_at":"2017-05-31T07:15:59.000+00:00","message":"更新 Jenkinsfile"},"commits":[{"id":"f0180cb5d2f71906bc3875f3526a85c73cd4bf35 ","short_id":"f0180cb5","title":"更新 Jenkinsfile","author_name":"Administrator","author_email":"admin@mail.com","created_at":"2017-05-31T07: 15:59.000+00:00","message":"更新 Jenkinsfile"}],"diffs":[{"old_path":"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 try\n {\t\n","new_file":false,"renamed_file":false,"deleted_file":false}],"compare_timeout ":false,"compare_same_ref":false}"
【问题讨论】:
-
你应该展示你已经尝试过的东西
-
这不只是一个 JSON 块吗?所有提交数据将位于 ["commits"][0]["id"]、["commits"][0]["short_id"] 等处。尝试使用类似jsonviewer.stack.hu 的内容以更友好的方式查看它格式。我不知道你为什么要尝试正则表达式 JSON 对象。
-
确实是 JSON,@kali 你用的是什么语言?在使用正则表达式之前尝试解析/解码 JSON。
标签: regex regex-greedy regex-group