Skip to contents

Select parts of a string: before, after or between patterns.

Usage

str_select(string, after = NULL, before = NULL)

Arguments

string

A character vector

after

A character single value (default = NULL), that will be the pattern to select after

before

A character single value (default = NULL), that will be the pattern to select before

Value

A character vector.

Examples


string <- "begin STRING1 TARGET STRING2 end"
#Select a string, before a pattern
str_select(string,before = "STRING2")
#> [1] "begin STRING1 TARGET"

#Select a string, after a pattern
str_select(string,after = "STRING1")
#> [1] "TARGET STRING2 end"

#Select a string, between two patterns
str_select(string,"STRING1","STRING2")
#> [1] "TARGET"