str_extract {stringr}R Documentation

Extract first piece of a string that matches a pattern.

Description

Extract first piece of a string that matches a pattern.

Usage

str_extract(string, pattern)

Arguments

string input character vector
pattern pattern to look for. See regex for description.

Value

character vector.

See Also

str_extract_all to extract all matches

Examples

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")

[Package stringr version 0.2 Index]