From 3b688ee8a5e7aecea193aa302ca5ab536c105bd4 Mon Sep 17 00:00:00 2001 From: Floris Vanderhaeghe Date: Wed, 20 Jun 2018 10:58:59 +0200 Subject: [PATCH] Elaborate on capturing groups (#615) Clarify the meaning and use of capturing groups. --- strings.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings.Rmd b/strings.Rmd index acf40e2..033316d 100644 --- a/strings.Rmd +++ b/strings.Rmd @@ -389,7 +389,7 @@ str_view(x, 'C[LX]+?') ### Grouping and backreferences -Earlier, you learned about parentheses as a way to disambiguate complex expressions. They also define "groups" that you can refer to with _backreferences_, like `\1`, `\2` etc. For example, the following regular expression finds all fruits that have a repeated pair of letters. +Earlier, you learned about parentheses as a way to disambiguate complex expressions. Parentheses also create a _numbered_ capturing group (number 1, 2 etc.). A capturing group stores _the part of the string_ matched by the part of the regular expression inside the parentheses. You can refer to the same text as previously matched by a capturing group with _backreferences_, like `\1`, `\2` etc. For example, the following regular expression finds all fruits that have a repeated pair of letters. ```{r} str_view(fruit, "(..)\\1", match = TRUE)