ore: Oniguruma regular expressions

Description Usage Arguments Value See Also Examples

View source: R/ore.R

Description

Create, test for, and print objects of class "ore", which represent Oniguruma regular expressions. These are length-1 character vectors with additional attributes, including a pointer to the compiled version.

Usage

1
2
3
4
5
6
ore(..., options = "", encoding = "auto", syntax = c("ruby", "fixed"))

is.ore(x)

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

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

The encoding that matching will take place in, a string string naming one of the encoding types discussed in Encoding, or "auto". In the latter case, the encoding of pattern will be used.

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.

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

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.

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

1
2
3
4
5
# This matches a positive or negative integer
ore("-?\\d+")

# This matches words of exactly four characters
ore("\\b\\w{4}\\b")

Example output

Oniguruma regular expression: /-?\d+/
 - 0 group(s)
 - unknown encoding
 - ruby syntax
Oniguruma regular expression: /\b\w{4}\b/
 - 0 group(s)
 - unknown encoding
 - ruby syntax

ore documentation built on Aug. 30, 2018, 9:05 a.m.