Vectorised over string and pattern.
See also
str_split_extract()
which splits up a string into pieces and extracts the results using a specified index position.
Examples
weekdays <- c(
"Monday_1", "Tuesday_2", "Wednesday_3", "Thursday_4",
"Friday_5", "Saturday_6", "Sunday_7"
)
str_extract_part(weekdays, before = TRUE, pattern = "_")
#> [1] "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"
#> [7] "Sunday"
str_extract_part(c("$159", "$587", "$897"), before = FALSE, pattern = "$")
#> [1] "159" "587" "897"