Create, test for, and print objects of class "ore"
, which represent
Oniguruma regular expressions. These are unit-length character vectors with
additional attributes, including a pointer to the compiled version.
ore(..., options = "", encoding = getOption("ore.encoding"),
syntax = c("ruby", "fixed"))is_ore(x)
# S3 method for ore
print(x, ...)
The ore
function returns the final pattern, with class
"ore"
and the following attributes:
A low-level pointer to the compiled version of the regular expression.
Options, copied from the argument of the same name.
The specified or detected encoding.
The specified syntax type.
The number of groups in the pattern.
Group names, if applicable.
The is_ore
function returns a logical vector indicating whether
its argument represents an "ore"
object.
One or more strings or dictionary labels, constituting a valid
regular expression after being concatenated together. Elements drawn from
the dictionary will be surrounded by parentheses, turning them into
groups. Note that backslashes should be doubled, to avoid them being
interpreted as character escapes by R. The ...
argument is ignored
by the print
method.
A string composed of characters indicating variations on the
usual interpretation of the regex. These may currently include "i"
for case-insensitive matching, and "m"
for multiline matching (in
which case "."
matches the newline character).
A string specifying the encoding that matching will take
place in. The default is given by the "ore.encoding"
option, which
is usually set automatically from the current locale when the package is
loaded, but can be modified if needed.
The regular expression syntax being used. The default is
"ruby"
, which reflects the syntax of the Ruby language, which is
very similar to that of Perl. An alternative is "fixed"
, for
literal matching without special treatment of characters.
An R object.
For full details of supported syntax, please see
https://raw.githubusercontent.com/k-takata/Onigmo/master/doc/RE. The
regex
page is also useful as a quick reference, since
PCRE (used by base R) and Oniguruma (used by ore
) have similar
features. See ore_dict
for details of the pattern dictionary.
# This matches a positive or negative integer
ore("-?\\d+")
# This matches words of exactly four characters
ore("\\b\\w{4}\\b")
Run the code above in your browser using DataLab