How to use capture() in rebus package?

Also see, if applicable, FAQ: Homework Policy

capture takes a character vector (i.e., a string) as an argument and returns

[a] character vector representing part or all of a regular expression.

So, in your example, the argument is

optional(DGT) %R%DGT) %R% capture(or('Y', 'YO','M','-', "")

optional is another function that takes a character vector and returns a regex

library(rebus)
optional(DGT)
#> <regex> [\d]?

Created on 2020-02-13 by the reprex package (v0.3.0)

The result is a lazy regex expressions that captures 1 or 0 digits, preferring zero. Buried in the documentation is that DGT is generic class for 'digit'.

%R% is a concatenation operator, named because %c% was considered too hard to type. (You can't make this up.)

Next comes another capture enclosing

or('Y', 'YO','M','-', "")

The or operator

or takes multiple character vector inputs and returns a character vector of the inputs separated by pipes

Putting it all together in loose terms;

Gimme a regular expression for something that may or may have in it a number before another number, but at least let there be one number followed by one of those other characters.

Regular expressions are totally great. They are hard but powerful. I can't for the life of me understand why someone would interpose a barrier to learning them effectively with this meta-regex tool.