Backreferences

String Manipulation with stringr in R

Charlotte Wickham

Assistant Professor at Oregon State University

Backreferences

REF1
<regex> \1
REF2
<regex> \2
String Manipulation with stringr in R

In a pattern

SPC %R% 
one_or_more(WRD) %R% 
SPC
String Manipulation with stringr in R

In a pattern

SPC %R% 
capture(one_or_more(WRD)) %R% 
SPC %R%
REF1
str_view("Paris in the the spring", 
  SPC %R% 
  capture(one_or_more(WRD)) %R% 
  SPC %R% 
  REF1)

chap_4_2.010.png

String Manipulation with stringr in R

In a replacement

str_replace("Paris in the the spring",
  pattern  = SPC %R% 
             capture(one_or_more(WRD)) %R% 
             SPC %R% 
             REF1,
  replacement = str_c(" ", REF1))
"Paris in the spring"
String Manipulation with stringr in R

Let's practice!

String Manipulation with stringr in R

Preparing Video For Download...