getex: Extract or remove a substring

View source: R/strings.R

getexR Documentation

Extract or remove a substring

Description

Extract of remove a substring matching a regular expression.

Usage

getex(x, pattern, ...)

Arguments

x

object from which strings are extracted. Will be coerced to a character by regexpr.

pattern

a regular expression whose matches in x are returned.

...

other arguments passed to regexpr.

Details

getex and getex_ can work as a pair to gradually extract information from a string.

Value

getex returns the substrings matched by pattern in x. getex_ returns the portion of x that is not matched.

Examples

library(magrittr)
# The following could be done with 'strsplit' but 'getex' can handle messier cases
progs <- c('SC BSc Honours Biology', 'Arts BA Ordinary Economics')
faculty <- progs  %>%  getex('^[^ ]+') %>% toupper
progs <- progs  %>% getex_('^[^ ]+ ')
degree <- progs %>% getex('^[^ ]+')

gmonette/spida2 documentation built on Aug. 11, 2024, 7:52 p.m.