Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

invert_match

Switch location of matches to location of non-matches.


Description

Invert a matrix of match locations to match the opposite of what was previously matched.

Usage

invert_match(loc)

Arguments

loc

matrix of match locations, as from str_locate_all()

Value

numeric match giving locations of non-matches

Examples

numbers <- "1 and 2 and 4 and 456"
num_loc <- str_locate_all(numbers, "[0-9]+")[[1]]
str_sub(numbers, num_loc[, "start"], num_loc[, "end"])

text_loc <- invert_match(num_loc)
str_sub(numbers, text_loc[, "start"], text_loc[, "end"])

stringr

Simple, Consistent Wrappers for Common String Operations

v1.4.0
GPL-2 | file LICENSE
Authors
Hadley Wickham [aut, cre, cph], RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.