2017-06-01 190 views
-2

在下面的內容中,我需要正則表達式來獲得匹配後的提交內容值「提交」: 請建議正則表達式模式來實現。正則表達式匹配後的詞

「{」 承諾 「:{」 ID 「:」 f0180cb5d2f71906bc3875f3526a85c73cd4bf35" , 「short_id」: 「f0180cb5」, 「稱號」: 「更新Jenkinsfile」, 「AUTHOR_NAME」: 「管理員」, 「AUTHOR_EMAIL」:「ABC @ mail.com「,」created_at「:」2017-05-31T07:15:59.000 + 00:00「,」message「:」更新Jenkinsfile「},」提交「:[{」id「:」f0180cb5d2f71906bc3875f3526a85c73cd4bf35「 ,「short_id」:「f0180cb5」,「title」:「更新Jenkinsfile」,「author_name」:「管理員」,「author_email」:「[email protected]」,「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 {\ t \ n「,」new_file「:false,」renamed_file「:false,」deleted_file「:false}],」compare_timeout「 :false,「compare_same_ref」:false}「

+0

你應該告訴你已經試過* *什麼是 – sudo

+0

這不僅僅是一個JSON塊?所有提交數據將位於[「提交」] [0] [「id」],[「提交」] [0] [「short_id」]等。嘗試使用類似http://jsonviewer.stack.hu /以更友好的格式查看它。我不知道爲什麼你會試圖對一個JSON對象進行regex。 –

+0

確實是JSON,@kali你在用什麼語言?嘗試在使用正則表達式之前解析/解碼JSON。 – sudo

回答

0

該正則表達式將捕獲"commits":的數組值。

注意這個工作的"commits"值必須是對象(從[{}]結束的數組。

我贊同威廉交叉的情緒,爲什麼你想正則表達式JSON。這會安全得多解析它訪問的commits值。

看到一個工作regex example here

/"commits":(\[\{.*?\}\])/g