Backreferences: Backreferences

Description Usage Format References See Also Examples

Description

Backreferences for replacement operations. These are used by replacement functions such as sub and stri_replace_first_regex, and by the stringi and stringr match functions such as stri_match_first_regex.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

Format

An object of class regex (inherits from character) of length 1.

References

http://www.regular-expressions.info/backref.html and http://www.rexegg.com/regex-capture.html

See Also

capture, for creating capture groups that can be referred to.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# For R's PCRE and Perl engines
REF1
REF2
# and so on, up to
REF9

# For stringi/stringr's ICU engine
ICU_REF1
ICU_REF2
# and so on, up to
ICU_REF9

# Usage
sub("a(b)c(d)", REF1 %R% REF2, "abcd")
stringi::stri_replace_first_regex("abcd", "a(b)c(d)", ICU_REF1 %R% ICU_REF2)

Example output

<regex> \1
<regex> \2
<regex> \9
<regex> $1
<regex> $2
<regex> $9
[1] "bd"
[1] "bd"

rebus.base documentation built on May 2, 2019, 5:14 a.m.