stringi (version 0.3-1)

stri_detect: Detect a Pattern Match

Description

These functions determine, for each string in str, if there is at least one match to a corresponding pattern.

Usage

stri_detect(str, ..., regex, fixed, coll, charclass)

stri_detect_fixed(str, pattern)

stri_detect_charclass(str, pattern)

stri_detect_coll(str, pattern, opts_collator = NULL)

stri_detect_regex(str, pattern, opts_regex = NULL)

Arguments

str
character vector with strings to search in
...
additional arguments passed to the underlying functions; stri_detect only
pattern,regex,fixed,coll,charclass
character vector defining search patterns; for more details refer to stringi-search
opts_collator
a named list with ICU Collator's settings as generated with stri_opts_collator; NULL for default settings; stri_detect_coll only
opts_regex
a named list with ICU Regex settings as generated with stri_opts_regex; NULL for default settings; stri_detect_regex only

Value

  • All the functions return a logical vector.

Details

Vectorized over str and pattern.

If pattern is empty, then the result is NA and a warning is generated.

stri_detect is a convenience function. It calls either stri_detect_regex, stri_detect_fixed, stri_detect_coll, or stri_detect_charclass, depending on the argument used. Unless you are a very lazy person, please call the underlying functions directly for better performance.

See also stri_startswith and stri_endswith for testing whether a string starts or ends with a given pattern match, respectively.

See Also

Other search_detect: stri_endswith, stri_endswith_charclass, stri_endswith_coll, stri_endswith_fixed, stri_startswith, stri_startswith_charclass, stri_startswith_coll, stri_startswith_fixed; stringi-search

Examples

Run this code
stri_detect_fixed(c("stringi R", "REXAMINE", "123"), c('i', 'R', '0'))
stri_detect_fixed(c("stringi R", "REXAMINE", "123"), 'R')

stri_detect_charclass(c("stRRRingi","REXAMINE", "123"),
   c("\\p{Ll}", "\\p{Lu}", "\\p{Zs}"))

stri_detect_regex(c("stringi R", "REXAMINE", "123"), 'R.')
stri_detect_regex(c("stringi R", "REXAMINE", "123"), '[[:alpha:]]*?')
stri_detect_regex(c("stringi R", "REXAMINE", "123"), '[a-zC1]')
stri_detect_regex(c("stringi R", "REXAMINE", "123"), '( R|RE)')
stri_detect_regex("stringi", "STRING.", opts_regex=stri_opts_regex(case_insensitive=TRUE))

Run the code above in your browser using DataLab