Learn R Programming

DescTools (version 0.99.37)

StrExtract: Extract Part of a String

Description

Extract a part of a string, defined as regular expression.

Usage

StrExtract(x, pattern, ...)

Arguments

x

a character vector where matches are sought, or an object which can be coerced by as.character to a character vector.

pattern

character string containing a regular expression (or character string for fixed = TRUE) to be matched in the given character vector. Coerced by as.character to a character string if possible. If a character vector of length 2 or more is supplied, the first element is used with a warning. Missing values are not allowed.

the dots are passed to the the internally used function regexpr(), which allows to use e.g. Perl-like regular expressions.

Value

A character vector.

Details

The function wraps regexpr and regmatches.

See Also

regexpr, regmatches

Examples

Run this code
# NOT RUN {
txt <- c("G1:E001", "No points here", "G2:E002", "G3:E003", NA)

# extract everything after the :
StrExtract(x=txt, pattern=":.*")
# }

Run the code above in your browser using DataLab