The pipe and the question mark

Intermediate Regular Expressions in R

Angelo Zehr

Data Journalist

This or that

lines <- c(
  "Karate Kid 2, Distributor: Columbia, 58 Screens",
  "Finding Nemo, Distributors: Pixar and Disney, 10 Screens",
  "Finding Harmony, Distributor: Unknown, 1 Screen",
  "Finding Dory, Distributors: Pixar and Disney, 8 Screens"
)
str_detect(lines, "Columbia|Pixar")
TRUE TRUE FALSE TRUE
Intermediate Regular Expressions in R

Making things optional

str_view(lines, pattern = "Distributor|Distributors")
str_view(lines, pattern = "Distributors?")

result of str_view

Intermediate Regular Expressions in R

Greedy vs. lazy

str_view("Toy Story 3 In Disney Digital 3D", ".*3")

result of str_view greedy

str_view("Toy Story 3 In Disney Digital 3D", ".*?3")

result of str_view lazy

Intermediate Regular Expressions in R

Let's practice!

Intermediate Regular Expressions in R

Preparing Video For Download...