## %######################################################%##
#                                                          #
####        Regex for data cleaning 1 - your turn        ####
#                                                          #
## %######################################################%##

# After running the code below: 

library(ggplot2)
library(dplyr)
library(stringr)

msleep %>% 
  select(name,genus) %>% 
  filter(str_detect(string = name,pattern = "rat"))


# How can we exclude muskrats from the matches?

# exclude muskrats from matches in the 'name' variable --------------------

# Look at resulting object, second row includes the Round-tailed muskrat

msleep %>% 
  select(name, genus) %>% 
  filter(str_detect(string = name, pattern = "rat"))

# modify the regexp that goes into the 'pattern' argument
# note the shorthand word boundary
msleep %>% 
  select(name, genus) %>% 
  filter(str_detect(string = name, pattern = "\\brat"))