capture: Create a capture group

Description Usage Arguments See Also Examples

Description

Used to save the matched value within the group for use later in the regular expression or to extract the values captured. Both named and unnamed groups can later be referenced using capture_group.

Usage

1
2
3

Arguments

...

shortcuts, R variables, text, or other rex functions.

name

of the group. Unnamed capture groups are numbers starting at 1 in the order they appear in the regular expression. If two groups have the same name, the leftmost group is the used in any reference.

See Also

group for grouping without capturing. Perl 5 Capture Groups https://perldoc.perl.org/perlre#Capture-groups

Other rex: %or%(), character_class(), counts, group(), lookarounds, not(), rex(), shortcuts, wildcards

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# Match paired quotation marks
re <- rex(
  # first quotation mark
  capture(quotes),

  # match all non-matching quotation marks
  zero_or_more(except(capture_group(1))),

  # end quotation mark (matches first)
  capture_group(1)
)

#named capture - don't match apples to oranges
re <- rex(
  capture(name = "fruit", or("apple", "orange")),
  "=",
  capture_group("fruit")
)

rex documentation built on Nov. 26, 2021, 5:21 p.m.