re_matches: Match function

Description Usage Arguments Value See Also Examples

Description

Match function

Usage

1
2
3
4
5
6
7
8
re_matches(
  data,
  pattern,
  global = FALSE,
  options = NULL,
  locations = FALSE,
  ...
)

Arguments

data

character vector to match against

pattern

regular expression to use for matching

global

use global matching

options

regular expression options

locations

rather than returning the values of the matched (or captured) string, return a data.frame of the match locations in the string.

...

options passed to regexpr or gregexpr

Value

if no captures, returns a logical vector the same length as the input character vector specifying if the relevant value matched or not. If there are captures in the regular expression, returns a data.frame with a column for each capture group. If global is TRUE, returns a list of data.frames.

See Also

regexp Section "Perl-like Regular Expressions" for a discussion of the supported options

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
string <- c("this is a", "test string")
re_matches(string, rex("test")) # FALSE FALSE

# named capture
re_matches(string, rex(capture(alphas, name = "first_word"), space,
  capture(alphas, name = "second_word")))
#   first_word second_word
# 1       this          is
# 2       test      string

# capture returns NA when it fails to match
re_matches(string, rex(capture("test")))
#      1
# 1 test
# 2 <NA>

rex documentation built on Nov. 26, 2021, 5:21 p.m.