regcapturedmatches: [.] Extract regular expression matches captured by names

Description Usage Arguments Value Source Examples

View source: R/regcapturedmatches.R

Description

regcapturedmatches.R: extracts captured matches from match data obtained by regexpr, gregexpr or regexec.

Usage

1

Arguments

x

(A list of) strings.

m

Parsed data, a result from a regular expression function.

Value

A list with captured matches

Source

The coded adapted from: regcapturedmatches.R on gist.github.com answer on stackoverflow.com. Originally written by: MrFlick

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# usage

x <- c("larry:35,M", "alison:22,F", "dave", "lily:55,F")
m <- regexpr("(.*):(\\d+),([MF])", x, perl = TRUE)
rez <- regcapturedmatches(x, m)
rez


regexp2df(x, "(.*):(\\d+),([MF])")


m <- regexpr("(?<name>.*):(?<age>\\d+),(?<gender>[MF])",
              x,
              perl = TRUE)
rez2 <- regcapturedmatches(x, m)
rez2

regexp2df(x, "(?<name>.*):(?<age>\\d+),(?<gender>[MF])")

GegznaV/spMisc documentation built on April 26, 2020, 5:59 p.m.