strextract {tmcn} | R Documentation

## Extract matched substrings by regular expression.

### Description

Extract matched substrings by regular expression.

### Usage

    strextract(string, pattern, invert = FALSE, ignore.case = FALSE,
      perl = FALSE, useBytes = FALSE)

### Arguments

`string` | A character vector.
`pattern` | A character string containing a regular expression to be matched in the given character vector.
`invert` | A logical value: if TRUE, extract the non-matched substrings.
`ignore.case` | If FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching.
`perl` | A logical value. Should perl-compatible regexps be used?
`useBytes` | A logical value. If TRUE the matching is done byte-by-byte rather than character-by-character.

### Value

A character vector with the matched or non-matched substrings.

### Author(s)

Jian Li <rweibo@sina.com>

### Examples

    txt1 <- c("\t(x1)a(aa2)a ", " bb(bb)")
    strextract(txt1, "\\([^)]*\\)")
    txt2 <- c("  Ben Franklin and Jefferson Davis", "\tMillard Fillmore")
    strextract(txt2, "(?<first>[[:upper:]][[:lower:]]+)", perl = TRUE)

[Package tmcn version 0.2-13 Index]