Elaborate on capturing groups (#615)

Clarify the meaning and use of capturing groups.
This commit is contained in:
Floris Vanderhaeghe 2018-06-20 10:58:59 +02:00 committed by Hadley Wickham
parent 9c236cddda
commit 3b688ee8a5
1 changed files with 1 additions and 1 deletions

View File

@ -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)