具有多個捕獲組的 R 中的正則表達式組捕獲 - Regex group capture in R with multiple capture-groups

問題:

In R, is it possible to extract group capture from a regular expression match?在 R 中,是否可以從正則表達式匹配中提取組捕獲? As far as I can tell, none of grep , grepl , regexpr , gregexpr , sub , or gsub return the group captures.據我所知, grepgreplregexprgregexprsubgsub gregexpr返回組捕獲。

I need to extract key-value pairs from strings that are encoded thus:我需要從這樣編碼的字符串中提取鍵值對:

\((.*?) :: (0\.[0-9]+)\)

I can always just do multiple full-match greps, or do some outside (non-R) processing, but I was hoping I can do it all within R. Is there's a function or a package that provides such a function to do this?我總是可以做多個完全匹配的 grep,或者做一些外部(非 R)處理,但我希望我可以在 R 中完成所有這些。是否有一個函數或包提供這樣的功能來做到這一點?


解決方案:

參考: https://stackoom.com/en/question/3zjH
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章