I have a text.
x = "(F1) sample text (F2) (F3) (S3)"
I want the below output.
"(F1)" "(F2)" "(F3)"
I know how to extract it via stringr package.
library(stringr)
str_extract_all(x, '\\(F[1-3]\\)')
I am curious how to implement negation of pattern in gsub( )
. Some of the programming languages support (?!
for inverse of regex pattern but it does not work in R. gsub("\\(F[1-3]\\)",'',x)