str_extract {stringr} | R Documentation |
Extract first piece of a string that matches a pattern.
str_extract(string, pattern)
string |
input character vector |
pattern |
pattern to look for. See regex for
description. |
character vector.
str_extract_all
to extract all matches
shopping_list <- c("apples x4", "flour", "sugar", "milk x2") str_extract(shopping_list, "\\d") str_extract(shopping_list, "[a-z]+") str_extract(shopping_list, "[a-z]{1,4}") str_extract(shopping_list, "\\b[a-z]{1,4}\\b")