[R] reg expr that retains only bracketed text from strings
nev||@@mo@ @end|ng |rom gm@||@com
Wed Jun 12 07:45:04 CEST 2019
I am trying to extract only the text contained in brackets from a vector of
not all of the strings contain closed bracketed text, they should return an
empty string or NA
this is what I have at the moment
substring(mystrings, regexpr("\\(|\\)", mystrings))
#this returns the whole string if there are no brackets.
 "ABC" "(B)C" "(C)"
# my desired desired output:
#  "" "(B)" "(C)"
many thanks for any suggestions
[[alternative HTML version deleted]]
More information about the R-help