invert_match: Switch location of matches to location of non-matches.

View source: R/locate.R

invert_matchR Documentation

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

numeric matrix of match locations, as from str_locate_all()

Value

Returns a numeric matrix giving locations of non-matches.

Examples

numbers <- "1 and 2 and 4 and 456"
and_loc <- str_locate_all(numbers, "and")[[1]]
str_sub(numbers, and_loc[, "start"], and_loc[, "end"])

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

csdaw/stringrb documentation built on Aug. 13, 2022, 10:55 p.m.