gmatch {lazy.symbolic}R Documentation

Return the captured value for each group

Description

Return the captured value for each group

Usage

gmatch(pat, s, whichg = 0)

Arguments

whichg

the group number to be retuned, or 0 to return all

pattern

pattern with groups

string

a string

Details

Return value is always a matrix: the i-j elemet is the captured value of the i-th group of the j-th match.

For example,
gmatch("(\w+)\[(\w+)\]", "a[b]+c[?]+d[2]")
will return

        match1 match2
 group1 "a"    "d"
 group2 "b"    "2"

with the following minfo attribute:

        match1 match2
  loc   "1"    "11"
  match "a[b]" "d[2]"

where loc contain the location of each match (as character) and match contains captured value of each match.

When there are no matches, a matrix of 0 rows and 0 columns will be returned.

Value

A matrix (groups x matches) consisting of the captured values

Examples

expr <- c("a[i,k]*b[k,j]+c[i,k]*d[k,k]+e[i,k]*f[p,j]")
pat <- "(\\w+)\\[(\\w+),(\\w+)\\]\\*(\\w+)\\[\\3,(\\w+)\\]"
gmatch( pat, expr )


[Package lazy.symbolic version 1.0.0.20250803 ]