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

View source: R/regexPieces.R

regexPiecesR Documentation

Extract named items from strings according to a regular expression.

Description

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

Usage

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


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"


MotusWTS/motusServer documentation built on Aug. 8, 2024, 10:23 p.m.