Enumerate exercise subparts with letters
This commit is contained in:
66
strings.Rmd
66
strings.Rmd
@@ -314,10 +314,10 @@ For example, I'll search for `\bsum\b` to avoid matching `summarise`, `summary`,
|
||||
|
||||
2. Given the corpus of common words in `stringr::words`, create regular expressions that find all words that:
|
||||
|
||||
1. Start with "y".
|
||||
2. End with "x"
|
||||
3. Are exactly three letters long. (Don't cheat by using `str_length()`!)
|
||||
4. Have seven letters or more.
|
||||
a. Start with "y".
|
||||
b. End with "x"
|
||||
c. Are exactly three letters long. (Don't cheat by using `str_length()`!)
|
||||
d. Have seven letters or more.
|
||||
|
||||
Since this list is long, you might want to use the `match` argument to `str_view()` to show only the matching or non-matching words.
|
||||
|
||||
@@ -360,14 +360,10 @@ str_view(c("grey", "gray"), "gr(e|a)y")
|
||||
|
||||
1. Create regular expressions to find all words that:
|
||||
|
||||
1. Start with a vowel.
|
||||
|
||||
2. That only contain consonants.
|
||||
(Hint: thinking about matching "not"-vowels.)
|
||||
|
||||
3. End with `ed`, but not with `eed`.
|
||||
|
||||
4. End with `ing` or `ise`.
|
||||
a. Start with a vowel.
|
||||
b. That only contain consonants. (Hint: thinking about matching "not"-vowels.)
|
||||
c. End with `ed`, but not with `eed`.
|
||||
d. End with `ing` or `ise`.
|
||||
|
||||
2. Empirically verify the rule "i before e except after c".
|
||||
|
||||
@@ -423,16 +419,16 @@ str_view(x, 'C[LX]+?')
|
||||
|
||||
2. Describe in words what these regular expressions match: (read carefully to see if I'm using a regular expression or a string that defines a regular expression.)
|
||||
|
||||
1. `^.*$`
|
||||
2. `"\\{.+\\}"`
|
||||
3. `\d{4}-\d{2}-\d{2}`
|
||||
4. `"\\\\{4}"`
|
||||
a. `^.*$`
|
||||
b. `"\\{.+\\}"`
|
||||
c. `\d{4}-\d{2}-\d{2}`
|
||||
d. `"\\\\{4}"`
|
||||
|
||||
3. Create regular expressions to find all words that:
|
||||
|
||||
1. Start with three consonants.
|
||||
2. Have three or more vowels in a row.
|
||||
3. Have two or more vowel-consonant pairs in a row.
|
||||
a. Start with three consonants.
|
||||
b. Have three or more vowels in a row.
|
||||
c. Have two or more vowel-consonant pairs in a row.
|
||||
|
||||
4. Solve the beginner regexp crosswords at <https://regexcrossword.com/challenges/beginner>.
|
||||
|
||||
@@ -454,19 +450,17 @@ str_view(fruit, "(..)\\1", match = TRUE)
|
||||
|
||||
1. Describe, in words, what these expressions will match:
|
||||
|
||||
1. `(.)\1\1`
|
||||
2. `"(.)(.)\\2\\1"`
|
||||
3. `(..)\1`
|
||||
4. `"(.).\\1.\\1"`
|
||||
5. `"(.)(.)(.).*\\3\\2\\1"`
|
||||
a. `(.)\1\1`
|
||||
b. `"(.)(.)\\2\\1"`
|
||||
c. `(..)\1`
|
||||
d. `"(.).\\1.\\1"`
|
||||
e. `"(.)(.)(.).*\\3\\2\\1"`
|
||||
|
||||
2. Construct regular expressions to match words that:
|
||||
|
||||
1. Start and end with the same character.
|
||||
|
||||
2. Contain a repeated pair of letters (e.g. "church" contains "ch" repeated twice.)
|
||||
|
||||
3. Contain one letter repeated in at least three places (e.g. "eleven" contains three "e"s.)
|
||||
a. Start and end with the same character.
|
||||
b. Contain a repeated pair of letters (e.g. "church" contains "ch" repeated twice.)
|
||||
c. Contain one letter repeated in at least three places (e.g. "eleven" contains three "e"s.)
|
||||
|
||||
## Tools
|
||||
|
||||
@@ -666,11 +660,9 @@ The second function will have the suffix `_all`.
|
||||
|
||||
1. For each of the following challenges, try solving it by using both a single regular expression, and a combination of multiple `str_detect()` calls.
|
||||
|
||||
1. Find all words that start or end with `x`.
|
||||
|
||||
2. Find all words that start with a vowel and end with a consonant.
|
||||
|
||||
3. Are there any words that contain at least one of each different vowel?
|
||||
a. Find all words that start or end with `x`.
|
||||
b. Find all words that start with a vowel and end with a consonant.
|
||||
c. Are there any words that contain at least one of each different vowel?
|
||||
|
||||
2. What word has the highest number of vowels?
|
||||
What word has the highest proportion of vowels?
|
||||
@@ -1048,8 +1040,8 @@ The main difference is the prefix: `str_` vs. `stri_`.
|
||||
|
||||
1. Find the stringi functions that:
|
||||
|
||||
1. Count the number of words.
|
||||
2. Find duplicated strings.
|
||||
3. Generate random text.
|
||||
a. Count the number of words.
|
||||
b. Find duplicated strings.
|
||||
c. Generate random text.
|
||||
|
||||
2. How do you control the language that `stri_sort()` uses for sorting?
|
||||
|
||||
Reference in New Issue
Block a user