Dấu gạch đứng và dấu hỏi

Regular Expressions nâng cao trong R

Angelo Zehr

Data Journalist

Cái này hoặc cái kia

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
Regular Expressions nâng cao trong R

Tạo phần tùy chọn

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

kết quả của str_view

Regular Expressions nâng cao trong R

Tham lam vs. lười

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

kết quả của str_view tham lam

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

kết quả của str_view lười

Regular Expressions nâng cao trong R

Hãy thực hành!

Regular Expressions nâng cao trong R

Preparing Video For Download...