Create a pre-compiled regular expression

Usage

re2(pattern, utf_8 = TRUE, case_sensitive = TRUE, posix_syntax = FALSE, dot_nl = FALSE, literal = FALSE, longest_match = FALSE, never_nl = FALSE, never_capture = FALSE, one_line = FALSE, perl_classes = FALSE, word_boundary = FALSE, log_error = FALSE, max_mem = 8388608, simplify = TRUE)

Arguments

pattern
regular expression pattern
utf_8
(true) text and pattern are UTF-8; otherwise Latin-1
case_sensitive
(true) match is case-sensitive (regexp can override with (?i) unless in posix_syntax mode)
posix_syntax
(false) restrict regexps to POSIX egrep syntax
dot_nl
(false) dot matches everything including new line
literal
(false) interpret string as literal, not regexp
longest_match
(false) search for longest match, not first match
never_nl
(false) never match \n, even if it is in regexp
never_capture
(false) parse all parens as non-capturing
one_line
(false) ^ and $ only match beginning and end of text, when posix_syntax == false this features are always enabled
perl_classes
(false) allow Perl's \d \s \w \D \S \W, when posix_syntax == false this features are always enabled
word_boundary
(false) allow Perl's \b \B (word boundary and not), when posix_syntax == false this features are always enabled
log_error
(false) log syntax and execution errors
max_mem
(see details) approx. max memory footprint of RE2
simplify
(true) return a object instead of a list when pattern length is 1.

Value

a pre-compiled regular expression

Description

Create a pre-compiled regular expression from a string.

Details

The max_mem option controls how much memory can be used to hold the compiled form of the regexp (the Prog) and its cached DFA graphs.

Once a DFA fills its budget, it flushes its cache and starts over. If this happens too often, RE2 falls back on the NFA implementation.

For now, make the default budget something close to Code Search.

Default maxmem = 8<<20 = 8388608;

Examples

regexp = re2("test") regexp
re2 pre-compiled regular expression pattern: test number of capturing subpatterns: 0 capturing names with indices: .match expression size: 8
re2_match("abc\ndef","(?s)(.*)")
.match .1 [1,] "abc\ndef" "abc\ndef"
re2_match("abc\ndef", re2("(?s)(.*)", never_nl = TRUE))
.match .1 [1,] "abc" "abc"
re2_detect("\n", re2(".", dot_nl = TRUE))
[1] TRUE
re2_detect("\n", ".")
[1] FALSE
get_number_of_groups(re2("(A)(v)",never_capture = TRUE))
[1] 0
re2_match("aaabaaaa",re2("(a|aaa)",longest_match = TRUE))
.match .1 [1,] "aaa" "aaa"
re2_match("aaabaaaa",re2("(a|aaa)",longest_match = FALSE))
.match .1 [1,] "a" "a"
re2_match("a+b", re2("a+b", literal = TRUE))
.match [1,] "a+b"
re2_detect("abc" , re2("abc", posix_syntax = TRUE))
[1] TRUE
re2("(?P<name>re)")
re2 pre-compiled regular expression pattern: (?P<name>re) number of capturing subpatterns: 1 capturing names with indices: .match name expression size: 8
## Not run: # # expect_error(re2("(?P<name>re)", posix_syntax = TRUE)) # ## End(Not run)