In this lesson, you will learn to:
Write regular expressions to match strings
Use special regular expression characters for general matching.
Use stringr()
functions to analyze text with regular expressions
Question 1:
Recall that the regular expression [abc]
matches the characters a
, b
, or c
.
What does [^abc]
match?
Question 2:
When it is not inside square brackets, the ^
symbol means “start of string”.
What will be returned by the following?
Question 3:
THe $
symbol in a regular expression means “end of string”.
What will be returned by the following?
What will the following outputs be?
my_str <- "The Dursleys of Number 4 Privet Drive were happy to say that they were perfectly normal, thank you very much."
str_extract_all(my_str, ".*")
str_extract_all(my_str, "\\w")
str_extract_all(my_str, "\\s")
str_extract_all(my_str, "[:alpha:]+")
str_extract_all(my_str, "[:alpha:]*\\.")
str_extract_all(my_str, "[wv]er[ey]")