capture

0th

Percentile

Create a capture group

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
capture(..., name = NULL)

capture_group(name)

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 http://perldoc.perl.org/perlre.html#Capture-groups

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

Aliases
  • capture
  • .
  • capture_group
Examples
# NOT RUN {
# 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")
)
# }
Documentation reproduced from package rex, version 1.1.2, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.