ID EN
Miscellaneous

regex

R Base 3.6.2

This help page documents the regular expression patterns supported by grep and related functions grepl, regexpr, gregexpr, sub and gsub, as well as by strsplit.

Details

A ‘regular expression’ is a pattern that describes a set of strings. Two types of regular expressions are used in R, extended regular expressions (the default) and Perl-like regular expressions used by perl = TRUE. There is also fixed = TRUE which can be considered to use a literal regular expression. Other functions which use regular expressions (often via the use of grep) include apropos, browseEnv, help.search, list.files and ls. These will all use extended regular expressions. Patterns are described here as they would be printed by cat: (do remember that backslashes need to be doubled when entering R character strings, e.g.from the keyboard). Long regular expression patterns may or may not be accepted: the POSIX standard only requires up to 256 bytes.

See Also

grep apropos browseEnv glob2rx help.search list.files ls and strsplit. The TRE documentation at http://laurikari.net/tre/documentation/regex-syntax/. The POSIX 1003.2 standard at http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html. The pcrepattern man page (found as part of http://www.pcre.org/original/pcre.txt) and details of Perl's own implementation at http://perldoc.perl.org/perlre.html.