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), just run the following:
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 <- find(value = "@") %>%
range(c("a", "z", 0, 9)) %>%
one_or_more() %>%
with_any_case()
x
#> [1] "(?i)(?:@)[a-z0-9]+"
# base R approach
unlist(regmatches(string, gregexpr(x, string)))
#> [1] "@OSKI" "@data2" "@pankote" "@oski2"
# stringr approach
# stringr::str_extract_all(string, x)
find
the @ tagrange
of characters, a through z and 0 through 9one_or_more
characters in the rangewith_any_case
thereby enabling case insensitive matching