問題:
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.據我所知, grep
、 grepl
、 regexpr
、 gregexpr
、 sub
或gsub
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 中完成所有這些。是否有一個函數或包提供這樣的功能來做到這一點?