GetCaptures: GetCaptures

Description Usage Arguments Details Value See Also Examples

View source: R/GetCaptures.R

Description

Split a chr string by capture groups according to a regular expression provided.

Usage

1
GetCaptures(s, pat)

Arguments

s

chr string

pat

chr string containing a regular expression with at least 1 capture '(', ')'

Details

The string is returned as a matrix of start and stop position of substrings. These substrings are labelled by which capture group they belong to. Substrings outside a capture are labelled as 0.

Nested capturing groups do not work.

Value

Num matrix indexing substrings of s. Each columns represents a substring. Row 1 is the label, Row 2 is the start, row 3 the stop letter of each substring. Substrings which are part of a capture are labelled with increasing numbers as they appear in s beginning with 1. Substrings which are not part of a capture are labelled with 0. If nothing was captured in chr s, NULL is returned.

See Also

Other CapturePattern module functions: CapturePatternUI, CapturePattern

Examples

1
2
3
4
5
s <- ">ENSG00000139083_8_61387.34117"
pat <- "^.*(SG.+?)1.*_(.+?)_.*$"

m <- GetCaptures(s, pat)
apply(m, 2, function(x) substr(s, x[2], x[3]))

mRcSchwering/shinyTools documentation built on May 21, 2017, 4:43 p.m.