ny Unicode newline
character (not just CR), and  \X  matches any number of Unicode characters
that form an extended Unicode sequence.

In UTF-8 mode, some Unicode properties may be supported via  \p{xx}  and
\P{xx}  which match characters with and without property  xx  respectively.
For a list of supported properties see the PCRE documentation, but for example
Lu  is ‘upper case letter’ and  Sc  is ‘currency symbol’. (This support
depends on the PCRE library being compiled with ‘Unicode property support’
which can be checked _via_ ` [ pcre_config
](/link/pcre_config?package=base&version=3.6.2) ` .)

The sequence  (?#  marks the start of a comment which continues up to the next
closing parenthesis. Nested parentheses are not permitted. The characters that
make up a comment play no part at all in the pattern matching.

If the extended option is set, an unescaped  #  character outside a character
class introduces a comment that continues up to the next newline character in
the pattern.

The pattern  (?:...)  groups characters just as parentheses do but does not
make a backreference.

Patterns  (?=...)  and  (?!...)  are zero-width positive and negative
lookahead _assertions_ : they match if an attempt to match the ` … ` forward
from the current position would succeed (or not), but use up no characters in
the string being processed. Patterns  (?<=...)  and  (?<!...)  are the
lookbehind equivalents: they do not allow repetition quantifiers nor  \C  in `
… ` .

` regexpr ` and ` gregexpr ` support ‘named capture’. If groups are named,
e.g., ` "(?<first>[A-Z][a-z]+)" ` then the positions of the matches are also
returned by name. (Named backreferences are not supported by ` sub ` .)

Atomic grouping, possessive qualifiers and conditional and recursive patterns
are not covered here.

##  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 ](/link/grep?package=base&version=3.6.2) ` , ` [ apropos
](/link/apropos?package=base&version=3.6.2) ` , ` [ browseEnv
](/link/browseEnv?package=base&version=3.6.2) ` , ` [ glob2rx
](/link/glob2rx?package=base&version=3.6.2) ` , ` [ help.search
](/link/help.search?package=base&version=3.6.2) ` , ` [ list.files
](/link/list.files?package=base&version=3.6.2) ` , ` [ ls
](/link/ls?package=base&version=3.6.2) ` and ` [ strsplit
](/link/strsplit?package=base&version=3.6.2) ` .

The TRE documentation at [ http://laurikari.net/tre/documentation/regex-
syntax/ ](http://laurikari.net/tre/documentation/regex-syntax/) .

The POSIX 1003.2 standard at [
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html
](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 ](http://www.pcre.org/original/pcre.txt)
), and details of Perl's own implementation at [
http://perldoc.perl.org/perlre.html ](http://perldoc.perl.org/perlre.html) .

Powered by  [ DataCamp ](https://www.datacamp.com/)