extract: Extract matching patterns from a string.

Description Usage Arguments Examples

Description

Extract matching patterns from a string.

Replace matched patterns in a string.

Usage

1
2
3
4
5
6
7

Arguments

x

A character vector to look for the patterns in.

pattern

A pattern to look for.

i

Index of a capture group to extract. If not specified, extract the whole match.

replacement

A pattern to replace, or a function to generate the replacement strings.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
### These examples are taken from stringr's doc (?str_extract) ###

shopping_list <- c("apples x4", "bag of flour", "bag of sugar", "milk x2")
rr4r_extract(shopping_list, "\\d")
rr4r_extract(shopping_list, "[a-z]+")
rr4r_extract(shopping_list, "[a-z]{1,4}")
rr4r_extract(shopping_list, "\\b[a-z]{1,4}\\b")

# Extract all matches
rr4r_extract_all(shopping_list, "[a-z]+")
rr4r_extract_all(shopping_list, "\\b[a-z]+\\b")
rr4r_extract_all(shopping_list, "\\d")

yutannihilation/rr4r documentation built on April 16, 2021, 8:40 a.m.