ore (version 1.7.4.1)

ore: Oniguruma regular expressions

Description

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.

Usage

ore(..., options = "", encoding = getOption("ore.encoding"),
  syntax = c("ruby", "fixed"))

is_ore(x)

# S3 method for ore print(x, ...)

Value

The ore function returns the final pattern, with class

"ore" and the following attributes:

.compiled

A low-level pointer to the compiled version of the regular expression.

options

Options, copied from the argument of the same name.

encoding

The specified or detected encoding.

syntax

The specified syntax type.

nGroups

The number of groups in the pattern.

groupNames

Group names, if applicable.

The is_ore function returns a logical vector indicating whether its argument represents an "ore" object.

Arguments

...

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.

options

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).

encoding

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.

syntax

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.

x

An R object.

See Also

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.

Examples

Run this code
# 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