submatch: Extract submatches from strings

Description Usage Arguments Value Examples

Description

Extract submatches from strings

Usage

1

Arguments

pattern

An extended regular expression (see regex) including at least one parenthesized subexpression

xs

Character vector with strings from which to extract the subexpressions matched by ‘pattern’

drop

If TRUE instead of returning a single-column or single-row matrix a vector is returned

Value

Returns a matrix containing submatches extracted from ‘xs’ according to ‘pattern’. The entry in row i and column j corresponds to the jth submatch extracted from ‘x[i]’. If ‘pattern’ did not match an element of ‘xs’, the corresponding row in the returned matrix will consist entirely of NA_character_ values. If ‘drop = TRUE’ single-column and single-row matrices are returned as vectors.

Examples

1
2
3
4
5
6
7
submatch(".*chr(\\\\d+)_(\\\\d+)",
         c("path_chr1_2/to/the_chr10_3_foo.txt",
           "path_chr1_2/to/the_chr7_5_bar.txt",
           "path_chrA_B/to/the_chrX_Y_baz.txt"))

# Submatch an expression within parentheses.
submatch("[(](.*)[)]", "foo (bar) baz")

cbaumbach/miscFun documentation built on May 13, 2019, 1:48 p.m.