character_class: Create character classes

Description Usage Arguments Functions See Also Examples

View source: R/character_class.R

Description

There are multiple ways you can define a character class.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
character_class(x)

one_of(...)

any_of(..., type = c("greedy", "lazy", "possessive"))

some_of(..., type = c("greedy", "lazy", "possessive"))

none_of(...)

except_any_of(..., type = c("greedy", "lazy", "possessive"))

except_some_of(..., type = c("greedy", "lazy", "possessive"))

range(start, end)

`:`(start, end)

exclude_range(start, end)

Arguments

x

text to include in the character class (must be escaped manually)

...

shortcuts, R variables, text, or other rex functions.

type

the type of match to perform.

There are three match types

  1. greedy: match the longest string. This is the default matching type.

  2. lazy: match the shortest string. This matches the shortest string from the same anchor point, not necessarily the shortest global string.

  3. possessive: match and don't allow backtracking

start

beginning of character class

end

end of character class

Functions

See Also

Other rex: %or%(), capture(), counts, group(), lookarounds, not(), rex(), shortcuts, wildcards

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# grey = gray
re <- rex("gr", one_of("a", "e"), "y")
grepl(re, c("grey", "gray")) # TRUE TRUE

# Match non-vowels
re <- rex(none_of("a", "e", "i", "o", "u"))
# They can also be in the same string
re <- rex(none_of("aeiou"))
grepl(re, c("k", "l", "e")) # TRUE TRUE FALSE

# Match range
re <- rex(range("a", "e"))
grepl(re, c("b", "d", "f")) # TRUE TRUE FALSE

# Explicit creation
re <- rex(character_class("abcd\\["))
grepl(re, c("a", "d", "[", "]")) # TRUE TRUE TRUE FALSE

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