Mention character class instead of escaping
@jennybc
This commit is contained in:
@@ -350,6 +350,14 @@ That lets you to avoid one layer of escaping:
|
|||||||
str_view(x, r"{\\}")
|
str_view(x, r"{\\}")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you're trying to match a literal `.`, `$`, `|`, `*`, `+`, `?`, `{`, `}`, `(`, `)`, there's an alternative to using a backslash escape: you can use a character class: `[.]`, `[$]`, `[|]`, \...
|
||||||
|
all match the literal values.
|
||||||
|
|
||||||
|
```{r}
|
||||||
|
str_view(c("abc", "a.c", "a*c", "a c"), "a[.]c")
|
||||||
|
str_view(c("abc", "a.c", "a*c", "a c"), ".[*]c")
|
||||||
|
```
|
||||||
|
|
||||||
The full set of metacharacters is `.^$\|*+?{}[]()`.
|
The full set of metacharacters is `.^$\|*+?{}[]()`.
|
||||||
In general, look at punctuation characters with suspicion; if your regular expression isn't matching what you think it should, check if you've used any of these characters.
|
In general, look at punctuation characters with suspicion; if your regular expression isn't matching what you think it should, check if you've used any of these characters.
|
||||||
|
|
||||||
@@ -885,3 +893,4 @@ You'll find stringi very easy to pick up because it follows many of the the same
|
|||||||
|
|
||||||
In the next chapter, we'll talk about a data structure closely related to strings: factors.
|
In the next chapter, we'll talk about a data structure closely related to strings: factors.
|
||||||
Factors are used to represent categorical data in R, data where there is a fixed and known set of possible values identified by a vector of strings.
|
Factors are used to represent categorical data in R, data where there is a fixed and known set of possible values identified by a vector of strings.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user