regexPieces: Extract named items from strings according to a regular...

Description Usage Arguments Value Author(s) Examples

View source: R/regexPieces.R

Description

FIXME (eventually): when the stringi package regex code can handle named subexpressions, use stri_extract_all_regex(..., simplify=TRUE)

Usage

1
regexPieces(rx, s)

Arguments

rx

Perl-type regular expression with named fields, as described in ?regex

s

character vector.

Value

a list of character vectors. Each vector corresponds to an item of s. The vector items are substrings of the input item corresponding to named capture groups in rx, in the order they appear in the input item. The vector names are those of the capture group. The same name might appear more than once in the vector. If an item in the input does not match any capture of rx, then its corresponding vector in the output is empty.

Author(s)

John Brzustowski jbrzusto@REMOVE_THIS_PART_fastmail.fm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
rx = "(?<ayes>a+)|(?<bees>b+)|(?<sees>c+)"
s = c("anybbody", "something", "aebbfcbggaa")
regexPieces(rx, s)
## returns:
##  [[1]]
##  ayes bees
##   "a" "bb"
##
##  [[2]]
##  named character(0)
##
##  [[3]]
##  ayes bees sees bees ayes
##   "a" "bb"  "c"  "b" "aa"

jbrzusto/motusServer documentation built on May 19, 2019, 8:19 a.m.