-2

In below content, I need the regex for get the commits content value after match "commits": Please suggest regex pattern for achieve that.

"{"commit":{"id":"f0180cb5d2f71906bc3875f3526a85c73cd4bf35","short_id":"f0180cb5","title":"Update Jenkinsfile","author_name":"Administrator","author_email":"abc@mail.com","created_at":"2017-05-31T07:15:59.000+00:00","message":"Update Jenkinsfile"},"commits":[{"id":"f0180cb5d2f71906bc3875f3526a85c73cd4bf35","short_id":"f0180cb5","title":"Update Jenkinsfile","author_name":"Administrator","author_email":"admin@mail.com","created_at":"2017-05-31T07:15:59.000+00:00","message":"Update 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}"

Kali
  • 21
  • 3
  • You should show what you have *tried* – sudo Jun 01 '17 at 04:59
  • Isn't this just a JSON block? All the commits data would sit at ["commits"][0]["id"], ["commits"][0]["short_id"], etc. Try using something like http://jsonviewer.stack.hu/ to view it in a friendlier format. I have no idea why you would be trying to regex a JSON object. – William Cross Jun 01 '17 at 05:01
  • Indeed it is JSON, @kali what language are you using? Try to parse / decode the JSON before using regex. – sudo Jun 01 '17 at 05:04

1 Answers1

0

This regex will capture the array value of "commits":.

Note for this to work, the value of "commits" must be an array of objects (starting with [{ and ending with }].

I echo the sentiments of William Cross, why are you trying to regex JSON. It would be much safer to parse it to access the value of commits.

See a working regex example here

/"commits":(\[\{.*?\}\])/g
sudo
  • 323
  • 3
  • 12