On Wed, 12 Jun 2019 15:45:04 +1000
nevil amos <[email protected]> wrote:
> # my desired desired output:
> # [1] "" "(B)" "(C)"
(function(s) regmatches(
s,
gregexpr('\\([^)]+\\)', s)
))(c("ABC","A(B)C","AB(C)"))
# [[1]]
# character(0)
#
# [[2]]
# [1] "(B)"
#
# [[3]]
# [1] "(C)"
This matches all substrings that start with an ( and are followed by
non-zero amount of non-) characters, then terminated by ). If there are
multiple such substrings, all are returned.
--
Best regards,
Ivan
______________________________________________
[email protected] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.