This vignette compiles a variety of examples, most taken straight from Stack Overflow. When possible, I will link the source of the example. To run any of the examples (i.e. copy/paste), load the following package:
library(RVerbalExpressions)
In this example, we want to extract every word that comes after a @, including the @. To do this, we will:
string <- "nowy commit, nowa przygoda @OSKI @data2 @pankote testujemy kod @oski2"
x <- rx() %>%
rx_find(value = "@") %>%
rx_alnum() %>%
rx_one_or_more()
# base R approach
unlist(regmatches(string, gregexpr(x, string)))
#> [1] "@OSKI" "@data2" "@pankote" "@oski2"
# stringr approach
# stringr::str_extract_all(string, x)
rx
rx_find
the @ tagone_or_more
characters in the range