match_tokens: Find Tokens that Match a Regex

Description Usage Arguments Value See Also Examples

View source: R/match_tokens.R

Description

Given a text, find all the tokens that match a regex(es). This function is particularly useful with replace_tokens.

Usage

1
match_tokens(x, pattern, ignore.case = TRUE, ...)

Arguments

x

A character vector.

pattern

Character string(s) to be matched in the given character vector.

ignore.case

logical. If TRUE the case of the tokens/patterns will be ignored.

...

ignored.

Value

Returns a vector of tokens from a text matching a specific regex pattern.

See Also

replace_tokens

Examples

1
2
3
4
with(DATA, match_tokens(state, c('^li', 'ou')))

with(DATA, match_tokens(state, c('^Th', '^I'), ignore.case = TRUE))
with(DATA, match_tokens(state, c('^Th', '^I'), ignore.case = FALSE))

Example output

[1] "should" "you"    "liar"   "about" 
[1] "is"    "it's"  "it"    "i"     "the"   "there" "then"  "i'm"  
[1] "I"     "There" "I'm"  

textclean documentation built on May 2, 2019, 7:22 a.m.